Php Codeigniter按选择组中的最新记录
如何告诉codeigniter在分组时选择最新的行(通过时间戳或id)。 目前它正在重新调整最旧的一个。 我正在创建一个活动提要并对类似的活动进行分组,但是最近的帖子是我想要展示的,而不是第一篇Php Codeigniter按选择组中的最新记录,php,mysql,codeigniter,group-by,Php,Mysql,Codeigniter,Group By,如何告诉codeigniter在分组时选择最新的行(通过时间戳或id)。 目前它正在重新调整最旧的一个。 我正在创建一个活动提要并对类似的活动进行分组,但是最近的帖子是我想要展示的,而不是第一篇 public function get_activity_notifications($users, $collections, $interests){ $this->db->from($this->notifications_table); $this->db
public function get_activity_notifications($users, $collections, $interests){
$this->db->from($this->notifications_table);
$this->db->where_in('data3', $interests);
$this->db->where_in('type', 'post');
$this->db->or_where_in('data', $collections);
$type_array = array('Replied','Commented', 'ending_soon');
$this->db->where_in('type', $type_array);
$this->db->or_where_in('instigator_id', $users);
$this->db->order_by("added", "desc");
$this->db->group_by(array("data3", "type"));
$query = $this->db->get();
print_r($this->db->last_query());
return $query->result_array();
}
$this->db->order\u byadded,desc;您正在使用的是正确的吗?它已经对从数据库返回的结果进行了排序,但这并不意味着从orderby中选择了最新的行,然后在group\u by之后添加order\u by