gpt4 book ai didi

php - PHP 中的订单函数不执行任何操作(CodeIgniter)

转载 作者:行者123 更新时间:2023-11-29 20:58:09 25 4
gpt4 key购买 nike

我使用 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;
}

最佳答案

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

例如:

替换$this->db->order_by('designment_joined', 'desc');$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);

关于php - PHP 中的订单函数不执行任何操作(CodeIgniter),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37455764/

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