Pagination issue - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: Pagination issue (/showthread.php?tid=71542) Pages:
1
2
|
Pagination issue - HarrysR - 08-27-2018 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! RE: Pagination issue - Wouter60 - 08-27-2018 Check the query (in your model): PHP Code: if ( !empty($pet_data) ) { RE: Pagination issue - HarrysR - 08-27-2018 (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.. RE: Pagination issue - InsiteFX - 08-28-2018 He's calling db limit after he is getting the database record. He should call db limit before calling the database for a record. RE: Pagination issue - HarrysR - 08-28-2018 (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) ) { RE: Pagination issue - HarrysR - 08-28-2018 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 (not necessary when there will be lots of entries but i wanna figure it out) is, what if i have only one page after filtering the data with the url parameters?! 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! RE: Pagination issue - Wouter60 - 08-28-2018 Controller (after $data["links"] = $this->pagination->create_links()): PHP Code: if ($pet_num <= $config['per_page']) $data['links'] = NULL; RE: Pagination issue - HarrysR - 08-28-2018 (08-28-2018, 08:10 AM)Wouter60 Wrote: Controller (after $data["links"] = $this->pagination->create_links()):Nope.. still the same.. RE: Pagination issue - Wouter60 - 08-28-2018 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']; RE: Pagination issue - HarrysR - 08-29-2018 (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.. |