This is a discussion on "Pagination with PHP and switch statement" within the PHP Forum section. This forum, and the thread "Pagination with PHP and switch statement are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Pagination with PHP and switch statement
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
||||
|
Pagination with PHP and switch statement
Hello there......I have a huge problem and have no idea how to sort it
I use a switch statement on my index.php page to display each of my pages (only some of them are shown to save space)
The link that appears in the browser window is http://www.mysite.com/index.php?page=newsitem?limit=2&page=2 but the default page is displayed. How do I sort this problem out? Do I need to use nested switch and if so how do I do it. The pagination script I am using is from http://www.allsyntax.com/tutorials/P...with-PHP/2.php I am sure if I didn't use the switch statement it would work but it seems very inefficient (been doing visual basic for the last 2 years at college). I have seen t done in dozens of websites including how google does it searches and need to know how to do it. Please help as I'm tearing my hair out here Last edited by AdRock; Jul 21st, 2006 at 23:51. |
|
|
|
|||
|
Re: Pagination with PHP and switch statement
Problem could be in the url, instead of;
http://www.mysite.com/index.php?page=newsitem?limit=2&page=2 try http://www.mysite.com/index.php?page=newsitem&limit=2&page=2 change that second ? for a & |
|
||||
|
Re: Pagination with PHP and switch statement
I tried that and it seemed to make sense but it still goes back to the default page
I am sure it's to do with the switch statement becuase the link http://www.mysite.com/index.php?page=newsitem&limit=2&page=2 isn't in the case include. How would I add that to the switch becuase the number of pages can increase? Thanks for your help p.s. If you need me to attach my code I will Last edited by AdRock; Jul 21st, 2006 at 23:43. Reason: adding text |
|
|||
|
Re: Pagination with PHP and switch statement
Hi AdRock,
I've just noticed that i missed something quite obvious last night. The reason that when you use index.php?page=newsitem&limit=2&page=2 it redirects to the default page is that you have page defined twice in the url so your $_GET vars only have two values, limit => 2 and page => 2, as there is no switch check in the switch statement called 2 it loads the default page. I think you need to rename the second page variable to something else and it should solve that problem |
|
||||
|
Re: Pagination with PHP and switch statement
Thanks Gee Bee, I did what you suggested and made a change of my own and now it works.
I do have another question you may be able to help with though. This is the change I made from $limit = 10 to $limit = 2 becuase my news items can be quite long so I only want 2 per page
|
|
|||
|
Re: Pagination with PHP and switch statement
your if statement could be written like this;
if(!isset($limit) || empty($limit) || !is_numeric($limit) || ($limit < 2) || ($limit > 50)) { $limit = 2; //default Not going to make a difference to how it performs but is more readable... for me anyway! the <a> tags look fine but you dont need amp; in them so they could just be <a href=apage.php?page=newsitem&limit=10&pagenum=1></a> Last edited by Gee Bee; Jul 22nd, 2006 at 08:19. |
![]() |
| Tags |
| pagination, php, switch, statement |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| CSS style switch | Heavensword | Web Page Design | 3 | Jul 24th, 2007 15:24 |
| Need small help with pagination | ofi | PHP Forum | 0 | Feb 7th, 2007 11:44 |
| Pagination without MySQL | Catie | PHP Forum | 3 | Jan 21st, 2007 23:06 |
| RSS feed pagination | deesto | Web Page Design | 0 | Dec 24th, 2006 02:31 |
| PHP pagination | robertboyle | PHP Forum | 1 | Jul 30th, 2006 18:08 |