PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have the following paging function that works perfectly apart from 2 things, the code is not mine, found on the net.
1. I want to display what page you are on ie Page 1 of 10. At the moment I can show the second number but not the first.
2. I have put the code into a table but am having problems with closing the table. All works as expected apart from when you get to the last page. I cant get the closing table tag to appear in the correct place. The code did NOT have tables to start with, I have added these in myself.
Lastly can the code be improved, made more effecient in any way?
With this the page number is always 1 behind, showing Page 0 of 5 when I am on page 1 etc, this happens all the way through. Also when you first go to the page I get an Undefined index: page, how do I fix that aswell.
$page = 1; // default
// make sure its set,
// and then that its ONLY a number,
// and then that the num is greater than 0
if (isSet($_GET['page']) && ctype_digit($_GET['page']) && $_GET['page'] > 0) {
$page = $_GET['page'];
}
$page = 1; // default
// make sure its set,
// and then that its ONLY a number,
// and then that the num is greater than 0
if (isSet($_GET['page']) && ctype_digit($_GET['page']) && $_GET['page'] > 0) {
$page = $_GET['page'];
}
I have added this to the very top of the page, outside of the function but it still shows Undefined index page on two lines. They are
Thanks for all the suggestions, I have managed to get rid of all the undefined index problems. I do however have another problem.
When setting $page = 1 it makes the part that displays Page 1 of 5 display correctly, however the clickable links show the current page as 2. Changing it to $page = 0 swaps things round with the links correct and Page 0 of 5 incorrect.
Is this an easy fix, any pointers please.