Codeigniter Pagination Delete Issue
i set my pagination with per_page=2. I have 5 records in my table.My 1 st page containd record 1,2 and my 2nd page containd the records 3,4 and my 3rd page containsthe record 5. I tried to delete the record in the 3rd page. After deleting it shows empty records list. But i want to move to the previous page. 开发者_StackOverflow社区Is it possible in codeigniter pagination
There's nothing built in to the CI pagination class, you'll have to do it yourself.
Each time you run the controller method (load the page), check if the result set is empty (and the page is not 1 or zero), if so - redirect to the previous page, preferably by calculating the last page number and going straight to it (or you could end up with a lot of redirects if the user goes to page 9999).
This should work but I have not tested it.
$last_page = floor($this->pagination->total_rows / $this->pagination->per_page);
You may want to look into finding another way to handle pagination as well, the Codeigniter pagination library sucks. Wish I had a link to share with something better but I don't, best to google/write something yourself that fits your needs.
You need to check last link, if it equal 1 (all_rows - uri_segment) in your exsimple 5-4, after then uri_segment - rer_page (4-2 = 2) and redirect to your_site/uri_segment = 2. I think this is rigth case!
精彩评论