Holow Holow - 3 months ago 13
PHP Question

Get the latest record with limit in codeigniter

My model

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

return $query->result();
}

Answer

Try this

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

return $query->result();
Comments