Php Programming Code Examples
Php > Site Navigation Code Examples
Navigate through records
Navigate through records
<?php
// Variables for navigating between previous and next record id
$previd = $id-1;
$nextid = $id+1;
// Your database connection code
$dbcnx = mysql_connect('localhost:', 'mysql','yourpass')
or die("Error Occurred");
mysql_selectdb("YourDB");
$query = "SELECT * FROM yourtable WHERE id='$id'";
$result = mysql_query($query, $dbcnx);
$row = mysql_fetch_array($result);
// Checking and displaying data
If (($id > 0) && ($id <= sizeof($row))) {
echo $row['your array'];
echo "<a href=\"page.php?id=$previd\">Previous</a>
<a href=\"page.php?id=$nextid\">Next</a>";
} else {
if ($id < 1) {
echo "Beginning of Record Set"." ";
echo "<a href=\"page.php?id=$nextid\">Next</a>";
} else {
echo "End of Record Set"." ";
echo "<a href=\"page.php?id=$previd\">Previous</a>";
}
}
?>