私はフレームワークとしてCodeIgniterを使用しています。 今はリストを注文したいが、DESCやASCには反応しない。注文関数はPHP(CodeIgniter)で何もしません
私のコードは次のとおりです。
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;
}
'ORDER BY'' GROUP BY'が動作しませんと。 'ORDER BY'でサブクエリを使用し、外側のselectクエリで' GROUP BY'を適用する必要があるかもしれません。 –
'ORDER BY'と' GROUP BY' **は一緒に働くべきです**。グループ前に注文してみましたか? – budwiser
PHPなどを使わずにSQLクエリを直接実行すると、正しい順序が得られますか? – jarlh