I'm doing some db querys using ActiveRecord and i need to paginate the results so i do a
$this->db->limit($pPagination['Start'], $pPagination['Length']);
but i don't get any results. Using $this->db->last_query();
it seems that CodeIgniter produces the following SQL
SELECT *
FROM (`viw_contacts`)
WHERE `user_id` = '1'
ORDER BY `contact_name` asc
LIMIT 0 OFFSET 15
which when i run it inside PHPMyAdmin also returns 0 rows.
But if i modify it an run :
SELECT *
FROM (`viw_contacts`)
WHERE `user_id` = '1'
ORDER BY `contact_name` asc
LIMIT 0, 15
Then i get the correct results. Any ideea why CodeIgniter generates this SQL and why it doesn't work?
I use CodeIgniter 1.7.3 and MySQL 5.1.41
Ok, found the issue.
It's
$this->db->limit($pPagination['Length'], $pPagination['Start']);
instead of
$this->db->limit($pPagination['Start'], $pPagination['Length']);
First param is the Length and second is the offset, not the other way around as i thought.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With