如何在CI Active Record中按MAX日期选择

inv*_*bot 1 php mysql activerecord codeigniter date

嗨,我的桌面结构如下

login_session_id, user_id, created_date, ci_cession_id, user_agent_string
Run Code Online (Sandbox Code Playgroud)

created_date字段是mysql_date_time.

我想从这个表中获取最新的一行(基于该created_date字段).如何使用CI Active记录?

Dan*_*orn 6

试试这个:

$this->db->select('*');
$this->db->from('** YOUR TABLE HERE **');
$this->db->order_by('created_date', 'desc');
$this->db->limit(1);
$query = $this->db->get();
Run Code Online (Sandbox Code Playgroud)

这应该通过选择表中的所有列(您需要指定),排序最近日期在顶部的所有行,然后将其限制为仅最顶行的最新条目.