MySQL Forums :: Quality Assurance :: php mysql pagination

Advanced Search

php mysql pagination
Posted by: Supernova Omega ()
Date: November 12, 2011 01:01PM

I want the NEXT button to disappear when the visitor reaches the last row of a table.

I created a php page which feeds from a mysql database table. Since the table has about 700 rows. I decided to paginate it. Everything worked well, you can click NEXT or Previous just fine. So the first page contains 100 rows, then there is a NEXT link. The problem is, I want the NEXT link to disappear after the last row is reached. Here is the code:

if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
$startrow = 0;
} else {
$startrow = (int)$_GET['startrow'];

$conn = mysql_connect("localhost", "root", "");
$sql = mysql_query("SELECT * FROM table LIMIT $startrow, 100");
while($result = mysql_fetch_array($sql)) {
echo "<b>" .$result["Word"] . "</b>: ";
echo $result["Definition"] . "<br />";

$prev = $startrow - 100;
echo '<h3>';
if ($prev >= 0)
echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.$prev.'">Previous</a>&nbsp;&nbsp;&nbsp;';
echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+100).'">Next</h3></a>';

Edited 1 time(s). Last edit at 11/12/2011 01:08PM by Supernova Omega.

Options: ReplyQuote

Subject Views Written By Posted
php mysql pagination 3849 Supernova Omega 11/12/2011 01:01PM
Re: php mysql pagination 1095 d batz 11/23/2011 01:30AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.