Just Sharing Knowledge on Robotics, Electronics and Programming

Friday, August 24, 2018

[SOLUTION] Select Database The N numbers Last or First Rows in Codeigniter


 
If you want to select the N last rows or N first rows, in codeigniter you can use the following script


$n = 100;
$this->db->limit(n); 
$this->db->order_by("id", "desc"); // N last rows 
$query = $this->db->get('my_table');
$myRow = $query->row();
 
 
$n = 100; 
$this->db->limit(n); 
$this->db->order_by("id", "asc"); // N first rows 
$query = $this->db->get('my_table');
$myRow = $query->row(); 
 

0 comments:

Post a Comment