MySQL Forums
Forum List  »  Quality Assurance

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:

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

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

<?PHP
$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
4717
November 12, 2011 01:01PM
1470
November 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.