Mysql 在Codeigniter中获取行替换
我如何在Codeigniter中得到这个?如果我尝试使用相同的方法,它会显示致命错误:非对象“fetch_row”,请帮助我使用codeigniter中的替代方法获取Mysql 在Codeigniter中获取行替换,mysql,codeigniter,Mysql,Codeigniter,我如何在Codeigniter中得到这个?如果我尝试使用相同的方法,它会显示致命错误:非对象“fetch_row”,请帮助我使用codeigniter中的替代方法获取fetch_row $sql = "SELECT DISTINCT attnDate FROM tbl_attendance ORDER BY attnDate"; $res = $g_link->query($sql); // mysqli query while ($row = $r
fetch_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];
}
获取$dates,如下所示:
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 rawAttendance(){
$data['date1'] = $this->AttendanceModel->raw_attendance_Status();
$this->load->view('attendance/rawAttendance', $data);
}
我想使用
result\u 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();
谢谢您,先生,result_array()直接返回此输出或需要使用foreach获取?您不需要像问题中所述从中获取任何内容!只要对结果执行
var\u dump()
,您就会知道您得到了什么!
$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();