PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
function pn_nav($table,$pn_var){
//$table: database table
//$pn_var: usualy the row id, it needs to be numeric.
if(!is_numeric($_GET["$pn_var"])){
echo "<p class=\"error\">The id needs to be a number.</p>\n";
}else{
$pn_id=$_GET["$pn_var"];
}
$navQuery="SELECT COUNT($pn_var) FROM $table";
$navResult=mysql_query($navQuery) or die (mysql_error());
$row=mysql_fetch_array($navResult);
//Previous
if($pn_id > 1){
$prev=$pn_id - 1;
echo "<a href=\"".$_SERVER['PHP_SELF']."?{$pn_var}={$prev}\">Previous</a> ";
}
// Next
if($pn_id < $row[0]){
$next=$pn_id + 1;
echo "<a href=\"".$_SERVER['PHP_SELF']."?{$pn_var}={$next}\">Next</a>\n";
}
}
Say the $pn_var is the id field. It counts the total so it knows the beginning and end. That way, there is no previous button on the first image and no next button on the last image.