codeigniter pagination – results remain same on every page
I’m using the Codeigniter pagination, but am encountering an issue.
The url changes on click, as in the limit updates e.g. displayAllUsers/10 to displayAllUsers/15, however the results remain same.
Here is my controller:
Anyone can spot what I am doing wrong?
Try doing your offset like this,
This way when you access your users, you start from the correct offset.
Let’s assume that you have 20 users in your table. When you first land on the page your $offset variable will be empty as there is no trailing numbers in your link (at $this->uri->segment(3)). So when you query your database for 5 users you start from 0 as the $offset variable is empty. In this circumstance your code would be:
Get 5 records starting from the 0th record.
When you use the pagination links however, the per_page variable you set adds a number to the end of your url and reloads the page. When this happens, your $offset variable gets given a number, in this case, it adds 5 each time.
Meaning get 5 records, starting from the 5th record.