Reputation: 805
Here is my code to display the counts of results obtained
My controller looks like this
$data['present'][]= $this->attendance_model->present_report_by_empid($v_employee->user_id,$date);
my model looks like this
public function present_report_by_empid($user_id = null,$date = null)
{
$temp = explode("-",$date);
$query='tbl_attendance.date_in';
$this->db->where('tbl_attendance.attendance_status', 1);
$this->db->where('tbl_attendance.user_id', $user_id);
$this->db->where("YEAR(tbl_attendance.date_in)",$temp[0]);
$this->db->where("MONTH(tbl_attendance.date_in)",$temp[1]);
$result = $this->db->get('tbl_attendance')->result_array();
$count=count($result); //counts number of rows
return $count;
}
view looks like this
<?php foreach($present as $key1 => $row){?>
<?php echo $row;?>
<?php }?>
when i use my code am getting result like this
but i want my result to be like this
Upvotes: 0
Views: 51
Reputation: 101
Try this:
$data['present'][$v_employee->user_id]= $this->attendance_model->present_report_by_empid($v_employee->user_id,$date);
$empl = array(
// empl_id => name,
1 => 'administrator',
2 => 'siraj',
3 => 'faizal',
4 => 'nesru',
)
foreach($empl as $key1 => $row){
echo $row;
if (!isset($data['present'][$key1])) {
echo ' '.$data['present'][$key1];
} else {
echo ' - ';
}
}
Upvotes: 1
Reputation: 357
It looks like you're building up the $data['present']
array with everyone's data first so you might want to do it like this :-
$data['present'][$v_employee->user_id] = $this->attendance_model->present_report_by_empid($v_employee->user_id,$date);
In the view you would pass in the $user_id
and then just echo the data for the correct user :-
<?php echo $present[$user_id] ;?>
Upvotes: 1