2016-05-26 19 views
0

私はフレームワークとして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; 
    } 
+0

'ORDER BY'' GROUP BY'が動作しませんと。 'ORDER BY'でサブクエリを使用し、外側のselectクエリで' GROUP BY'を適用する必要があるかもしれません。 –

+0

'ORDER BY'と' GROUP BY' **は一緒に働くべきです**。グループ前に注文してみましたか? – budwiser

+0

PHPなどを使わずにSQLクエリを直接実行すると、正しい順序が得られますか? – jarlh

答えて

0

が同じ値を与える数(user_to_designment.user_id)あるdesignment_joined。違いを見ることはできません。 PHPMyAdminで直接クエリを実行し、結果を確認してください。 orderby節でフィールド名を変更してチェックしてみてください。

例:

$this->db->order_by('user_to_designment.user_id', 'desc');$this->db->order_by('designment_joined', '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); 
+0

お返事ありがとうございます。しかし、私は動作しませんでした。私はそれを交換したが、私はまだ同じを表示する –

+0

それは動作していますか? – Karthikeyani

+0

いいえ、動作しません。以前と同じです。 –

関連する問題