我怎么把这个放进编码器里?如果我尝试了同样的方法,它会显示致命错误:non-object'fetch_row',请帮助我在codeigniter中使用alternative forfetch_row
。
$sql = "SELECT DISTINCT attnDate
FROM tbl_attendance
ORDER BY attnDate";
$res = $g_link->query($sql); // mysqli query
while ($row = $res->fetch_row()) {
$dates[] = $row[0];
}
获取$日期,如下所示:
Array
(
[0] => 2015-11-25
[1] => 2015-11-29
[2] => 2015-11-30
[3] => 2015-12-01
[4] => 2015-12-02
[5] => 2015-12-03
[6] => 2015-12-05
[7] => 2015-12-06
[8] => 2015-12-07
[9] => 2015-12-08
[10] => 2015-12-09
[11] => 2015-12-10
[12] => 2015-12-12
)
当我在codeigniter中尝试时:
型号:
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();
}
控制器:
public function rawAttendance(){
$data['date1'] = $this->AttendanceModel->raw_attendance_Status();
$this->load->view('attendance/rawAttendance', $data);
}
最佳答案
我想用result_array()
可以帮你!
$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();