2016-08-07 6 views
0

私のモデルでは限界が最新のレコードを取得しますCodeIgniterの

public function getLogs() 
{ 
    $this->db->limit(5); 
    $query = $this->db->get('tbllogs'); 

    return $query->result(); 
} 
+0

問題は何ですか?質問は何ですか? – Tpojka

+0

Zayn Aliは既にそれに答えました – Holow

答えて

1

この

$this->db->order_by("id", "desc"); 
$this->db->limit(5); 
$query = $this->db->get('tbllogs'); 

return $query->result(); 

それともoldためとlatestロジックはそれでorderByクエリパラメータを使用してビュー内の2つのリンクを作成してみます。お使いのコントローラメソッドで

<a href="/controller/method?orderBy='old'">Old</a> 
<a href="/controller/method?orderBy='latest'">Latest</a> 

if ($this->input->get('orderBy') == 'old') { 
    $this->db->order_by("id", "asc"); 
} else { 
    $this->db->order_by("id", "desc"); 
} 

$this->db->limit(5); 
$query = $this->db->get('tbllogs'); 

return $query->result(); 
+0

何か提案がありますか?私は私のビューにいくつかのボタンを配置し、それをクリックしたときに最も古いログが表示されますか? – Holow

+0

@Holow私は私の答えを更新しました –

+0

ありがとう、それは私を助けてくれました! – Holow