function emp_attendence() {
$dept = $this->session->userdata("department") ;
function filter($value)
{
$dept = "'$value'" ;
return $dept;
}
$query = $this->db->query('select emp_id from employee where department IN ('.implode( ",",array_map("filter",$dept) ) .') order by emp_id asc');
$emp = $query->result_array() ; // echo '<pre>' ; print_r($emp[0]['emp_id']) ; exit();
foreach( $emp as $emp_id) {
foreach( $emp_id as $id) {
$query = "SELECT count(attendence) as total_attendence
FROM employee
INNER JOIN attendence ON employee.emp_id = attendence.employee_id
WHERE emp_id='$id' AND MONTH(date)=MONTH(CURDATE())";
$query = $this->db->query($query);
$query = $query->result_array() ;
}
}
return $query ;
}
This above code is a model in codeigniter , my aim is to get total attendance for each employee in database , Code is running fine but i am getting value of my last record return by query not all records !!!
foreach( $emp as $emp_id) {define$attendence_array = array();and then instead of$query = $query->result_array() ;write$attendence_array[] = $query->result_array() ;and then instead ofreturn $query ;writereturn $attendence_array ;and then check$attendence_arrayby printing it out that it comes fine or not what you want