我正在使用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是一个计数(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/