";
} else {
$piece .= "$i";
}
$piece .= "</a>\n";
$start = $start+$amm;
$numSoFar++;
$wholePiece .= $piece;
}
$wholePiece .= "\n";
$wheBeg = $begin+1;
$wheEnd = $begin+$amm;
$wheToWhe = "".$wheBeg."</b> - ";
if ($totalrows <= $wheEnd) {
$wheToWhe .= $totalrows."</b>";
} else {
$wheToWhe .= $wheEnd."</b>";
}
$sqlprod = " LIMIT ".$begin.", ".$amm;
} else {
$wholePiece = "Sorry, no records to display.";
$wheToWhe = "0</b> - 0</b>";
}
return array($sqlprod,$wheToWhe,$wholePiece);
}
/*
| Usage |
NOTE!: This is just an example and WON'T WORK if you include
this in your code, comment it out or delete it :)
*/
$criterea = " WHERE column=value AND column_2=value_2";
$sql = "SELECT COUNT(*) AS totalrows FROM table".$criterea;
//get the total amount of rows returned
$arr = mysql_fetch_array(mysql_query($sql));
/*
Call the function:
I've used the global $_GET array as an example for people
running php with register_globals turned 'off' :)
*/
$navigate = pageBrowser($arr[totalrows],10,10,"&name=value",$_GET[numBegin],$_GET[begin],$_GET[num]);
//execute the new query with the appended SQL bit returned by the function
$sql = "SELECT * FROM table".$criterea.$navigate[0];
$rs = mysql_query($sql);
//the indication of which rows are being browsed. Eg. listing 1-10 of 100 results.
echo "Listing ".$navigate[1]." of ".$totalrows." results.</p>";
//the navigation bar returned by the function
echo "
".$navigate[2]."</p>";
//loop and display the limited records being browsed
while ($arr = mysql_fetch_array($rs)) {
echo $arr[column_1]." ".$arr[column_2]."
";
}
//the navigation bar at the bottom again
echo "
".$navigate[2]."</p>";
/*
I hope this can come in handy :)
*/
?>