...

View Full Version : Pagination Error (Need Assistance)



Salchester
07-21-2007, 01:54 AM
Hiya Guys,

I'm using the following code to dynamically create pages if total records in a database reach over 8.

Only if nothing is in the database, then "Next Screen" button is still clickable, taking you to another page. How do I disable the "Next Screen" button if nothing is in the database, and display a error message saying so?

Also, if the records in the database equal the quantity to display per page, the "Next Screen" button is still clickable, taking the user to another page. How do I disable the "Next Screen" button if the records in the database equal the quantity to display per page?


<link rel="stylesheet" type="text/css" href="Index.css" />

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("TS", $con);

$perpage = 8;

$start = (isset($_GET['id'])) ? $_GET['id'] : 0;

$TotalRec = mysql_result(mysql_query("SELECT COUNT(*) FROM Buttons"), 0);

$select = "SELECT * FROM Buttons LIMIT $start, $perpage";
$result = mysql_query($select) or die(mysql_error());

echo '<div id="Bar"></div>';
echo '<div id="Container">';

# Dislay your rows here in the loop
while($row = mysql_fetch_array($result))
{
echo '<div class="But">';
echo '<img id="ButImg" src="ButImg.bmp">';
echo '<div id="ButTitle">' . $row['Title'] . '</div>';
echo '<div id="ButBody">' . $row['Description'] . '</div>';
echo '<img id="But_tl" src="But_tl.gif">';
echo '<img id="But_tr" src="But_tr.gif">';
echo '<img id="But_bl" src="But_bl.gif">';
echo '<img id="But_br" src="But_br.gif">';
echo '</div>';
}

if($start == 0)
{
echo '<div id="ButPrevDis">';
echo '<div id="NavDis">Previous Screen</div>';
echo '</div>';
}
else
{
echo '<div id="ButPrevEna">';
echo "<a href=\"./Display.php?id=" . ($start - $perpage) . "\" class=\"NavEna\">Previous Screen</a>";
echo '</div>';
}

$page = ($_GET['id'] / $perpage) + 1;
$total = ceil($TotalRec / $perpage);

echo '<div id="Pag">';
echo '<div id="PagCap">' . $page . " of " . $total . '</div>';
echo '<img id="Pag_tl" src="Pag_tl.gif">';
echo '<img id="Pag_tr" src="Pag_tr.gif">';
echo '<img id="Pag_bl" src="Pag_bl.gif">';
echo '<img id="Pag_br" src="Pag_br.gif">';
echo '</div>';

if($start == $TotalRec - 1)
{
echo '<div id="ButNextDis">';
echo '<div id="NavDis">Next Screen</div>';
echo '</div>';
}
else
{
echo '<div id="ButNextEna">';
echo "<a href=\"./Display.php?id=" . ($start + $perpage) . "\" class=\"NavEna\">Next Screen</a>";
echo '</div>';
}

echo '</div>';
?>

Any help would be grateful, as this is driving me nuts!!!

_Aerospace_Eng_
07-21-2007, 02:00 AM
Using mysql_num_rows() will return the number of rows that where found matching the query.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum