![]() |
Pagination, offset issue - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Pagination, offset issue (/showthread.php?tid=26363) |
Pagination, offset issue - El Forum - 01-12-2010 [eluser]1cookie1[/eluser] hi I'm having problems with a pagination script. Ive searched the forums and found a lot of uesful stuff but alas i can't get my script to work. ![]() article came close and I adopted some their code - but still my pagination links don't work correctly. OK, my code: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> There are 17 rows in total in my db, table = 'books' My test URIs are: http://localhost/CIgniter/index.php/books/index/1 http://localhost/CIgniter/index.php/books/index/2 http://localhost/CIgniter/index.php/books/index/3 http://localhost/CIgniter/index.php/books/index/4 If I type these manually in my address bar in my browser I get correct results; i.e. the script pulls records: 1 - 5 6 - 10 11 - 15 & lastly records 16 & 17, displaying these to the screen. (please see attached ss) My links display like: 1 2 3 > Last Clicking on link 2 displays: http://localhost/index.php/books/index/5, in my browser address bar and in the page body I get a 404 error The requested URL /index.php/books/index/5 was not found on this server. Clicking on link 3 displays: http://localhost/index.php/books/index/10, followed by 404 error The requested URL /index.php/books/index/10 was not found on this server. And so on. Click on Last and get: http://localhost/index.php/books/index/15 404! Not found. It's not the uri segment number as I have confirmed that this is correct by manually typing the uri s above. For a relatively simple concept such as offset and limit, I'm struggling a bit. Help please. ![]() Pagination, offset issue - El Forum - 01-13-2010 [eluser]Unknown[/eluser] Hi I am also new to codeigniter but If you try Quote:$config['query_string_segment'] = 'offset'; as Code: $this->load->library('pagination'); and then you will get offset in your url and may be you don't need following code Code: if (isset($page) && is_numeric($page)) See if this helps. Pagination, offset issue - El Forum - 01-13-2010 [eluser]1cookie1[/eluser] [quote author="Gurudutt" date="1263413786"]Hi I am also new to codeigniter but If you try $config['query_string_segment'] = 'offset'; $config['page_query_string'] = TRUE;[/quote] hi Gurudutt the code above produces a php notice: undefined constant 'query_string_segment' and 'page_query_string'. One way to get it working is as follows: forget about the books_model class completely; bin it. In the 'new' controller: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); and in the 'new' books_view file: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> It takes away the model->view->controller aspect turning the script into controller->view; which is a little disapointing, but hey, it works a charm over here! The offset clause in the MySQL query takes a bit of getting used to (fiddling with)! hope this helps best wishes :-) Pagination, offset issue - El Forum - 01-13-2010 [eluser]mcr_rm[/eluser] I am confused a little by this. Firstly the pagination class always passes increments of your per page value in the uri right? how have you got it to pass 1/2/3/4 when in per pages of five it should be passing nothing followed by /5/10/15. Secondly you are delaring $page=null in the index function however I don't see anywhere where $page is being set to the uri segment. And I don't know why you need it anyway as the offset is actually the bit passed in the uri usually i.e. 5/10/15 and so you just pass $this->uri->segment(3) to the database call for the offset surely? I think the only bit that is really confusing for me is how you got manually typing it in the browser to work? as at no point can I see the setting of $page from the uri to multiply the per page for the offset (which is needless anyways). Are yousurw when you type the recors it is infact pulling the right records in sequence? Pagination, offset issue - El Forum - 01-13-2010 [eluser]maria clara[/eluser] hi to all, i am also new in CI. i also encountered that pagination problem. try this in your model. these scripts i used for my pagination and it works. hope you can get an idea with this. Code: $page = $this->input->post('page'); hope this could help you. regards, maria ![]() Pagination, offset issue - El Forum - 01-14-2010 [eluser]1cookie1[/eluser] [quote author="mcr_rm" date="1263442151"]I am confused a little by this. Firstly the pagination class always passes increments of your per page value in the uri right? [/quote] I'm glad you point that out! I may never have thought of it that way if you hadn't! :-) Quote:how have you got it to pass 1/2/3/4 when in per pages of five it should be passing nothing followed by /5/10/15.I type 1/2/3/4 MANUALLY in the url i.e. http://localhost/CIgniter/index.php/books/index/1 //pulls records 2 - 6 http://localhost/CIgniter/index.php/books/index/2 //pulls records 7 - 11 http://localhost/CIgniter/index.php/books/index/3 //pulls records 12 - 16 http://localhost/CIgniter/index.php/books/index/4 //pulls record 17 Not what I'm looking for! My explanation probably confused you, sorry. :-) If I type: http://localhost/CIgniter/index.php/books/index/0, i.e. an offset of 0, then the script pulls records 1 - 5, as you may or may not expect. Quote:Secondly you are delaring $page=null in the index function however I don't see anywhere where $page is being set to the uri segment. And I don't know why you need it anyway as the offset is actually the bit passed in the uri usually i.e. 5/10/15 and so you just pass $this->uri->segment(3) to the database call for the offset surely? I agree, NOW! This was purely something I tried out from post #1. I may have been going off at a different tangent! ![]() Quote:I think the only bit that is really confusing for me is how you got manually typing it in the browser to work? as at no point can I see the setting of $page from the uri to multiply the per page for the offset (which is needless anyways). I confused the issue with the whole multiplying thing. My script originally started off without it and the $page=NULL variable (again from post#1). The one thing Iv'e learnt in all of this is that whatever is in the 3rd segment (or whatever file structure your using) of the uri - its effectively the offset and the query will pull records starting from that value! hope this helps. ;-) Pagination, offset issue - El Forum - 01-14-2010 [eluser]mcr_rm[/eluser] [quote author="1cookie1" date="1263481752"] I'm glad you point that out! I may never have thought of it that way if you hadn't! :-) [/quote] No Need for the sarcasm, what I was trying to say (poorly) was exactly what you are saying. Firstly CI pagination class passes the offset in the uri not a page number i.e. multples of your per page rather than the 1/2/3/4. So to be clear the 1/2/3/4 was never working properly with the class links? You seem to have it now but didn't before and I was confused at how you got anything working properly with that code. Essentially forget the multiple rubbish and simply pass in the uri segment with the offset to your db query via a model or whatever is doing the db call. Pagination, offset issue - El Forum - 01-14-2010 [eluser]1cookie1[/eluser] [quote author="mcr_rm" date="1263487652"][quote author="1cookie1" date="1263481752"] No Need for the sarcasm, what I was trying to say (poorly) was exactly what you are saying. [/quote] No sarcasm intended! Quote: Firstly CI pagination class passes the offset in the uri not a page number i.e. multples of your per page rather than the 1/2/3/4. Correct! The class links did not work correctly. Quote:You seem to have it now but didn't before and I was confused at how you got anything working properly with that code. I admit, the code was poorly constructed, but to be fair.. I'm new to CI and so am going to look foolish on first attempt? Knowlege is something you leave with, not come in with! Quote:Essentially forget the multiple rubbish and simply pass in the uri segment with the offset to your db query via a model or whatever is doing the db call. Correct! ![]() |