订单函数在PHP中没有任何作用(CodeIgniter)(Order function doesn't do anything in PHP (CodeIgniter))

编程入门 行业动态 更新时间:2024-10-03 17:13:45
订单函数在PHP中没有任何作用(CodeIgniter)(Order function doesn't do anything in PHP (CodeIgniter))

我正在使用CodeIgniter作为框架。 现在我想订购一个列表,但它不会对DESC或ASC做出反应。

我的代码是:

function get_community($limit, $smallicon = false) { $this->db->select('user_to_designment.user_id, count(user_to_designment.user_id) as designment_joined, user_profiles.first_name, user_profiles.middle_name, user_profiles.last_name'); $this->db->from('user_to_designment'); $this->db->join('user_to_user_profile', 'user_to_designment.user_id = user_to_user_profile.user_id'); $this->db->join('user_profiles', 'user_to_user_profile.profile_id = user_profiles.profile_id'); $this->db->group_by('user_id'); $this->db->order_by('designment_joined', 'desc'); $this->db->limit($limit); $communitys = $this->db->get()->result_array(); foreach ($communitys as &$community) { if($smallicon){ $community['image'] = self::get_small_user_icon_by_id($community['user_id']); }else{ $community['image'] = self::get_big_user_icon_by_id($community['user_id']); } } return $communitys; }

I'm using CodeIgniter as a framework. Now I want to order a list but it doesn't react on DESC or ASC.

My code is:

function get_community($limit, $smallicon = false) { $this->db->select('user_to_designment.user_id, count(user_to_designment.user_id) as designment_joined, user_profiles.first_name, user_profiles.middle_name, user_profiles.last_name'); $this->db->from('user_to_designment'); $this->db->join('user_to_user_profile', 'user_to_designment.user_id = user_to_user_profile.user_id'); $this->db->join('user_profiles', 'user_to_user_profile.profile_id = user_profiles.profile_id'); $this->db->group_by('user_id'); $this->db->order_by('designment_joined', 'desc'); $this->db->limit($limit); $communitys = $this->db->get()->result_array(); foreach ($communitys as &$community) { if($smallicon){ $community['image'] = self::get_small_user_icon_by_id($community['user_id']); }else{ $community['image'] = self::get_big_user_icon_by_id($community['user_id']); } } return $communitys; }

最满意答案

designment_joined是一个count(user_to_designment.user_id) ,它将给出相同的值。 所以你看不出差异。 直接在PHPMyAdmin中尝试查询并查看结果。 还尝试在orderby子句中更改字段名称并检查。

例如:

替换$this->db->order_by('designment_joined', 'desc'); with $this->db->order_by('user_to_designment.user_id', 'desc'); 并检查。

更新的代码:

$this->db->select('user_to_designment.user_id, count(user_to_designment.user_id) as designment_joined, user_profiles.first_name, user_profiles.middle_name, user_profiles.last_name'); $this->db->from('user_to_designment'); $this->db->join('user_to_user_profile', 'user_to_designment.user_id = user_to_user_profile.user_id'); $this->db->join('user_profiles', 'user_to_user_profile.profile_id = user_profiles.profile_id'); $this->db->order_by('user_to_designment.user_id', 'desc'); $this->db->limit($limit);

designment_joined is a count(user_to_designment.user_id) which will give the same value. So you can not see the difference. Try the query directly in PHPMyAdmin and see the result. Also try to change the field name in orderby clause and check.

eg :

Replace $this->db->order_by('designment_joined', 'desc'); with $this->db->order_by('user_to_designment.user_id', 'desc'); and check.

Updated Code:

$this->db->select('user_to_designment.user_id, count(user_to_designment.user_id) as designment_joined, user_profiles.first_name, user_profiles.middle_name, user_profiles.last_name'); $this->db->from('user_to_designment'); $this->db->join('user_to_user_profile', 'user_to_designment.user_id = user_to_user_profile.user_id'); $this->db->join('user_profiles', 'user_to_user_profile.profile_id = user_profiles.profile_id'); $this->db->order_by('user_to_designment.user_id', 'desc'); $this->db->limit($limit);

更多推荐

本文发布于:2023-08-04 20:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1422226.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有任何   函数   订单   作用   Order

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!