displaying link for next page of results, even when not available

He has: 688 posts

Joined: Feb 2001

Hi. I've got one specific problem to fix. I have a bit of code that will display previous and next links when displaying data from my mySQL database. It correctly doesn't display a previous arrow if it's on the first display page, but for any page which has at least 1 result, it always displays a next arrow , even if there is no next page. Here's an example link.

http://www.pstvalumni.com/directory/class.php?classyear=1981

Here's the code I'm using. Can somebody please help me adjust this code slightly to avoid displaying the next link when there isn't a next page to go to? (I can list more of the code if that helps). Thanks.

<?php
if ($page['0']) print \"<b><a href='$PHP_SELF?classyear=\".($classyear).\"&page=\".($page-1).\"'><img src=\\"bleft.gif\\" border=0></a></b>\n\";
echo \"   \";
if (@mysql_num_rows(
$result)) print \"<a href='$PHP_SELF?classyear=\".($classyear).\"&page=\".($page+1).\"'><img src=\\"bright.gif\\" border=0></a></b>\n\";
?>

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

try
if (mysql_num_rows($result)>$page)

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.