First, replace:
- $rowsPerPage = 3;
-
$pageNum = 1;
-
$offset = ($pageNum - 1) * $rowsPerPage;
with
- $rowsPerPage = 3;
-
if(isset($_GET['page']))
-
{
-
$pageNum = mysql_real_escape_string($_GET['page']);
-
}
-
else
-
{
-
$pageNum = 1;
-
}
-
$offset = ($pageNum - 1) * $rowsPerPage;
Second, remove:
- if(isset($_GET['page']))
-
{
-
$pageNum = $_GET['page'];
-
}
And here are some tips:
-
ALWAYS sanitize user input before you put it into MYSQL. You are connecting to MYSQL using the root account and you are putting user strings into queries. A user could easily do something like www.site.com/page.php?page='; delete from user_groups; which would get you fired :( Use mysql_real_escape_string before pasting strings into queries.
- Use the [ code ] tags you have in the bytes.com message editor to paste code, that way it's easier to read your code and it's easier to tell you where the problem is because that tag will add line numbers.
- Break PHP from HTML because if in a month you need to change something in your page, you won't even know where to start! Use a templating system such as Smarty or
at least don't output HTML using PHP variables.
- While in production, you should
ALWAYS set PHP to report all errors, by setting error_reporting to "E_ALL | E_STRICT" and display_errors to "on" in your php.ini file (don't forget to restart APACHE after this). If you would have done that, you would have easily seen your error! It's on the first post in the PHP section of this website, it's a sticky post telling you to turn on error reporting. If you don't have access to php.ini check out this:
http://bytes.com/forum/thread629295.html