2016-06-28 54 views
0

我要顯示具有最高保留數的前9個位置。所以我必須有一個計數$this->db->group_by('t.id_pl'),然後按該計數的數量進行排序。在CodeIgniter中計算的分組數

我已經成功地做到這一點,但我不明白的地方我應該把計數:

function select_pop() 
{ 
    $this->db->select('s.place as place, s.price as price, s.title as title');    
    $this->db->from('Places AS s'); 
    $this->db->join('Reservations AS t', 't.id_pl= s.place', 'INNER');  
    $this->db->group_by('t.id_pl'); 
    $this->db->order_by(''); 
    $this->db->limit(9);  
    $result = $this->db->get(); 
    return $result; 
} 

有什麼建議?

回答

0

,你可以在你的SELECT語句如下─一樣

$this->db->select('count(t.id_pl) as reservation_count,s.place as place, s.price as price, s.title as title'); 

然後加計數ORDER BY您可以使用喜歡 -

$this->db->order_by('reservation_count','DESC'); 

我希望這將幫助你..