2013-05-28 47 views
1
$pag = $this->db->get('articles', $config['per_page'], $this->uri->segment(4));   
$data['records'] = $pag->result(); 

我已經與笨和活動記錄排序DB結果

$pag = $this->db->get('articles', $config['per_page'], $this->uri->segment(4));   
$this->db->order_by('published', 'ASC'); 
$data['records'] = $pag->result(); 

嘗試要麼使用ASCdesc我沒有看到任何改變。

我在這裏做錯了什麼?

感謝

回答

3

問題是:您在要求訂購之前執行查詢。
訂購之前,然後執行查詢
當您:db->get您執行查詢,如果你有一個where條件或訂單條件,你必須把它放在get命令之前。
試試這個

$this->db->order_by('published', 'ASC'); 
$pag = $this->db->get('articles', $config['per_page'], $this->uri->segment(4)); 
$data['records'] = $pag->result(); 

DOCUMENTATION

3

試試這個。將order_by語句移到頂部。

$this->db->order_by('published', 'ASC'); 
$pag = $this->db->get('articles', $config['per_page'], $this->uri->segment(4));   
$data['records'] = $pag->result();