• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
$this->db->limit() working differently?

#1
Lightbulb 
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.
Reply

#2
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) 
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply

#3
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;
}
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
2 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.