First Function
Posted: Sun Mar 23, 2008 1:33 pm
I just made this function to generate "previous" and "next" links. It works but am I missing anything?
Code: Select all
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";
}
}