Reputation: 579
Getting error to view result_array
, please help me to get this view.
Model:
public function raw_attendance_Status() {
$this->db->distinct();
$this->db->select('attnDate');
$this->db->from('tbl_attendance');
$this->db->order_by('attnDate');
$query = $this->db->get();
return $query->result_array();
}
Controller:
public function rawAttendance(){
$data['Dates'] = $this->AttendanceModel->raw_attendance_Status();
$this->load->view('attendance/rawAttendance', $data);
}
View:
foreach ($Dates as $k=>$v) {
$dates[$k] = date('d-M-Y', strtotime($v));
}
$heads = "<table border='1'>\n";
$heads .= "<tr><th>TraineeID</th><th>" . join('</th><th>', $dates) . "</th></tr>\n";
$tdata .= "</table\n";
$dates variable output:
array(13) { [0]=> array(1) { ["attnDate"]=> string(10) "2015-11-25" } [1]=> array(1) { ["attnDate"]=> string(10) "2015-11-29" } [2]=> array(1) { ["attnDate"]=> string(10) "2015-11-30" } [3]=> array(1) { ["attnDate"]=> string(10) "2015-12-01" } [4]=> array(1) { ["attnDate"]=> string(10) "2015-12-02" } [5]=> array(1) { ["attnDate"]=> string(10) "2015-12-03" } [6]=> array(1) { ["attnDate"]=> string(10) "2015-12-05" } [7]=> array(1) { ["attnDate"]=> string(10) "2015-12-06" } [8]=> array(1) { ["attnDate"]=> string(10) "2015-12-07" } [9]=> array(1) { ["attnDate"]=> string(10) "2015-12-08" } [10]=> array(1) { ["attnDate"]=> string(10) "2015-12-09" } [11]=> array(1) { ["attnDate"]=> string(10) "2015-12-10" } [12]=> array(1) { ["attnDate"]=> string(10) "2015-12-12" } }
Upvotes: 3
Views: 10923
Reputation: 1961
Since your result is returning in multi dimensional array use:
$dates[] = date('d-M-Y', strtotime($v['attnDate']));
instead of:
$dates[] = date('d-M-Y', strtotime($v));
Upvotes: 1
Reputation: 7105
Are you sure attnDate field is date type?
because this error
strtotime() expects parameter 1 to be string, array given
show when you use other type or your value is null
in view print $Dates and show me results
Upvotes: 0