Pagination issue |
Hey guys,
I've created the pagination in codeigniter but i have a problem on getting the entries. While in the first page as i saw it gets the proper entries, when i change the page i can not see the right ones. I also placed a date function in order to check the creation date of the entries and as i see the further i go in the pagination, the entries are not getting older (if you know what i mean). Moreover if the entries are less than the "per_page" value then i keep getting pagination links in the view file. I also have a "GET" filtering function for the entries. [EDIT]: Changed it a bit but still not working as i wish. I get in the second page and i don't get a thing.. All i get is an empty page, like it's not getting any data. Here's my controller file: Code: public function index(){ My model: Code: public function get_filtered_pets($limit, $start){ Any ideas?! Thanks! //Life motto if (sad() == true) { sad().stop(); develop(); }
Check the query (in your model):
PHP Code: if ( !empty($pet_data) ) { (08-27-2018, 09:00 AM)Wouter60 Wrote: Check the query (in your model): All i get is my query. "SELECT * FROM "table" JOIN etc... etc..." And everything looks ok.. //Life motto if (sad() == true) { sad().stop(); develop(); }
He's calling db limit after he is getting the database record.
He should call db limit before calling the database for a record. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(08-28-2018, 04:25 AM)InsiteFX Wrote: He's calling db limit after he is getting the database record. I've added the limit before the data call and still nothing. Code: if ( !empty($pet_data) ) { //Life motto if (sad() == true) { sad().stop(); develop(); }
Well i think i managed to solve it by calculating the $limit and $offset in my controller.
As you can see here https://pastebin.com/7pGj9dnQ A last thing i wanna ask and might be a silly one so be kind ![]() E.g. i filter the data, i only get 12 entries (as the per_page configuration) and i still get pagination links in the bottom even if the second page is empty. Any ideas on that?! Thanks! //Life motto if (sad() == true) { sad().stop(); develop(); }
Controller (after $data["links"] = $this->pagination->create_links()):
PHP Code: if ($pet_num <= $config['per_page']) $data['links'] = NULL;
I checked a site of my own that uses the pagination library.
You have: PHP Code: $start = $page * $config['per_page']; And you use $start as the offset. In my website, I use $page as the offset, which works fine. Try if you get the correct results if you do this: PHP Code: //$start = $page * $config['per_page']; (08-28-2018, 10:35 AM)Wouter60 Wrote: I checked a site of my own that uses the pagination library. I got the right results (as i can see) by making this: Code: $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 1; But the major problem is that when i filter the data and theoretically some of them may be less than the per_page config, i keep getting pagination links shown.. //Life motto if (sad() == true) { sad().stop(); develop(); } |
Welcome Guest, Not a member yet? Register Sign In |