$nav_next_id = $page_id + 1;
$sql = "SELECT page FROM plm WHERE id = '$nav_next_id'"; {
$result = mysql_query($sql);
while ($next_page = mysql_fetch_array($result))
{
if($page_id + 1 > 24)
{
$goto_next_page = 'some_page.php';
}
else
{
$goto_next_page = $next_page['page_title'];
}
}
}
Basically a very straight forward next page button on simple site. Using the ID in the MYSQL table I can determine the next page from the current page.
All works well until I come to the last page. Which is page 24.
So i put an if in the loop saying if the page is > 24 go to some_page.php.
I am echoing $goto_next_page in my html.
However nothing is echoed from page 24, all other pages work fine. What wrong with this script?
———UPDATE—————- THIS IS HOW I GOT IT TO WORK ——————
if($cur_page_id == 24)
{
$goto_next_page = 'some_page.php';
}
else
{
$sql = "SELECT page FROM plm WHERE id = '$nav_next_id'"; {
$result = mysql_query($sql);
while ($next_page = mysql_fetch_array($result))
{
$goto_next_page = $next_page['page_title'];
}
}
}
Perhaps you meant to use the pre-increment operator:
Effectively, this means:
This operator as well as its brother operator (the post-increment operator) both add 1 to the variable. However, the pre-increment operator adds one and then returns the new value. The post-increment operator, on the other hand, returns the value of the variable and then increments it by 1.
The reason why your code doesn’t work is that
$page_id + 1 > 24doesn’t increment$page_idso it always remains the same. This makes sense because if you did:You wouldn’t expect
$page_idto be incremented. You would expect$ato be 1 more than$page_id, but you’d expect$page_idto be the same.