db->select('notice_x_user.*,notice.*,-6ren">
gpt4 book ai didi

php - 通过在 codeigniter 中不使用 Group by 来排序

转载 作者:行者123 更新时间:2023-11-30 21:25:03 25 4
gpt4 key购买 nike

$loginuserID = $this->session->userdata("loginuserID");

$this->db->select('notice_x_user.*,notice.*,classes.*,sub_courses.*,,notice.status as studentStatus,notice.date as noticeDate');
$this->db->from('notice_x_user');
$this->db->join('notice','notice_x_user.noticeID = notice.noticeID', 'LEFT');
$this->db->join('classes', 'classes.ClassesID = notice.classesID', 'LEFT');
$this->db->join('sub_courses', 'sub_courses.sub_coursesID = notice.sub_coursesID', 'LEFT');
$wheres = "(notice_x_user.userID = '".$loginuserID."' and notice_x_user.usertype = 'Support') or notice.userID = '".$loginuserID."'";
$this->db->where($wheres);
$this->db->order_by('notice.noticeID', 'DESC');
$this->db->group_by('notice.noticeID');

我加入了四个表,在那里我得到了正确的数据,但问题是在使用 group by 时 order by 不起作用。那么,我该怎么做呢?请帮助我。

谢谢

最佳答案

use select_max for getting the max noticeID

$this->db->select('notice_x_user.*,notice.*,classes.*,sub_courses.*,,notice.status as studentStatus,notice.date as noticeDate');
$this->db->select_max('notice.noticeID' , 'noticeID');
$this->db->from('notice_x_user');
$this->db->join('notice','notice_x_user.noticeID = notice.noticeID', 'LEFT');
$this->db->join('classes', 'classes.ClassesID = notice.classesID', 'LEFT');
$this->db->join('sub_courses', 'sub_courses.sub_coursesID = notice.sub_coursesID', 'LEFT');
$wheres = "(notice_x_user.userID = '".$loginuserID."' and notice_x_user.usertype = 'Support') or notice.userID = '".$loginuserID."'";
$this->db->where($wheres);
$this->db->order_by('noticeID', 'DESC');
$this->db->group_by('notice.noticeID');

关于php - 通过在 codeigniter 中不使用 Group by 来排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59562869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com