I'm trying to create a dynamic page navigation system within a portfolio. It should count the number of pages within a particular job (rows linked via a join) and produce a next/previous arrangement. This isn't pagination as such as I needed more control over what appeared on which page.
It's nearly working except that it can't seem to count!! Say there are a total of 3 pages - it's only counting up to 2 and I'm not sure why. Here's the code:
Code: Select all
$num_rows = mysql_num_rows($result);
if ($page_number == 1){
}
if ($page_number != $num_rows){
$next = $page_number + 1;
}else{
$next = $page_number;
}
if ($page_number != 1){
$prev = $page_number - 1;
}else{
$prev = 1;
}
echo '<a href="'. $_SERVER['PHP_SELF'] . '?id=' . $id;
echo '&page_number=' . $prev . '">prev</a> ';
echo $page_number. '/' . $num_rows ;
echo ' <a href="'. $_SERVER['PHP_SELF'] . '?id=' . $id;
echo '&page_number=' . $next . '">next</a>';prev 1/3 next
If you click "next" you go to page 2. But you can't then get to page 3. You can click on prev and go back to page 1.
Any suggestions about what I'm missing to force it to count all of the rows?