这是我的代码,我从tblTest中询问end_date。End_date是一个日期时间。下面是代码,但是它给了我一个错误:
$this->db->select(date('end_date'));
$this->db->where('topActive', 'true');
$this->db->order_by('end_date');
$this->db->group_by('end_date');
$q = $this->db->get('tblTest');
误差:
Unknown column 'UTC1107_07pm30UTC' in 'field list'
SELECT `UTC1107_07pm30UTC`
FROM (`tblTest`)
WHERE `topActive` = 'true'
GROUP BY `UTC1107_07pm30UTC`
ORDER BY `UTC1107_07pm30UTC`
我做错了什么?
谢谢
在你的select方法中,你传递了一个日期对象。此方法接受需要返回的列的名称。end_date
是您的列名,所以使用它。
$this->db->select('end_date');
这是最终工作的查询:
$this->db->select("DATE(end_date) as my_end_date", FALSE);
$this->db->where('topActive', 'true');
$this->db->order_by('my_end_date');
$this->db->group_by('my_end_date');
$q = $this->db->get('tblTest');