Click to See Complete Forum and Search --> : Pagination don't show next if no more results


Markbad311
02-27-2006, 08:10 PM
I have this little pagination script and it works for the most part. but right now I am trying to get it to only show a "Previous" link if there is rows before and Next only if rows after the limit specified.

I got it to not show the previous link when no rows before but it won't show next and previous on the next page only previous. which leads me to believe it is a if{}else{} failure on my part. but where? and how can I accomplish this if how I am doing it is wrong.

the code in question. (snippets of the important stuff)

$table_name = "guestbook";
$table_2 = "guest_comments";
$show = 6;
$start = (isset($_GET['start']))?$_GET['start']:0;
/////////
$sql2 = mysql_query("SELECT COUNT(*) FROM $table_name");
$howmany = mysql_fetch_row($sql2) or die("Error Line 8." . mysql_error());
global $guest_block;

$guest_block = "<table class=\"gbook\" width=\"70%\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\">";
$sql = "SELECT * FROM $table_name ORDER BY id DESC LIMIT $start, $show";
$result = mysql_query($sql, $connection) or die (mysql_error());
$count = 0;
while($row = mysql_fetch_array($result)) {

$count++;
// get individual elements from the array
// all kinds of elements here...
}
////////
//after the while then I have this portion again to build the link.
////////
$total = $start + $show;
$next = $start + $show;
$prev = $start - $show;
////////
if(($total < $howmany[0]) && ($prev > 0))
{
$guest_block .= "
<div align=\"center\">
<a href=\"$_SERVER[PHP_SELF]?start=$prev\">Previous $show</a>
| <a href=\"$_SERVER[PHP_SELF]?start=$next\">Next $show</a>
</div>
<p>Showing Listings $start to $total of $howmany[0].</p>";
}

if ($prev < 0)
{
$guest_block .= "
<div align=\"center\">
<a href=\"$_SERVER[PHP_SELF]?start=$next\">Next $show</a>
</div>
<p>Showing Listings $start to $total of $howmany[0].</p>";

}
else
{
$guest_block .= "
<div align=\"center\">
<a href=\"$_SERVER[PHP_SELF]?start=$prev\">Previous $show</a>
</div>
<p>Showing Listings $start to $total of $howmany[0].</p>";
}

}




Please any help will be appreciated. I can't have it just always display a link because it is a bad query if there are no rows left or none previous to what is currently being shown...

Markbad311
02-27-2006, 08:14 PM
to reinterate it seems that only the last if {} block is working.

I need an if else block that is like this

if (from 0-10 rows){
No previous link
}

elseif (10 -2nd to last set of results) {
// show next AND previous links.
}
else (2nd to last set-no more rows left) {
// Only previous link
}

Thanks.

Markbad311
02-28-2006, 06:27 PM
<BUMP>

Still definetly need some help on this one. Please anyone that has any idea how I an remedy this issue please do... Many Thanks.. :cool:

Markbad311
03-01-2006, 04:24 PM
<BUMP>

is this an imposible thing to do or something?