Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter按选择组中的最新记录_Php_Mysql_Codeigniter_Group By - Fatal编程技术网

Php Codeigniter按选择组中的最新记录

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

如何告诉codeigniter在分组时选择最新的行(通过时间戳或id)。 目前它正在重新调整最旧的一个。 我正在创建一个活动提要并对类似的活动进行分组,但是最近的帖子是我想要展示的,而不是第一篇

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