CodeIgniter Forums
$this->db->limit() working differently? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: $this->db->limit() working differently? (/showthread.php?tid=66615)



$this->db->limit() working differently? - Ornis - 11-13-2016

Hi

I had to fix an application while upgrading from version 3.1.0 to 3.1.2 because active record $this->db->limit() apparently works differently:

Code:


Code:
$this->db->limit(0,1);
$arr_settings = $this->db->get('settings')->result_array();


produced under system 3.1.0:
Code:
SELECT * FROM `settings



produced under system 3.1.2:
Code:
SELECT * FROM `settings` LIMIT 1, 0


I couldn't find this in the change log.

Thanks.


RE: $this->db->limit() working differently? - InsiteFX - 11-13-2016

The limit and offset were reversed from mysql, see it below and in the Users Guide.

As far as I remember it has always been this way back to version 1.6x

PHP Code:
$this->db->limit(1020);  // Produces: LIMIT 20, 10 (in MySQL.  Other databases have slightly different syntax) 



RE: $this->db->limit() working differently? - XtreemDeveloper - 12-21-2017

MySQL data fetch query as limit and offset. You can use this code for limit query
function getRecords($searchData)
{
$search_index = '2';
$limit = "10";
$this->db->limit($limit,$search_index);
$this->db->where('status','Active');
$this->db->order_by($this->table.'.add_date', 'desc');
$this->db->where('approve_status','Approved');
$this->db->where('type','Blog');
$query = $this->db->get($this->table);
$result = $query->result();
return $result;
}