In conclusion our page would look something like this:
<?php
function pagenav() {
global $limit,$offset,$numpage,$where;
if ($where) {
$safewhere=urlencode($where);
}
echo "
<TABLE CELLPADDING=0 BORDER=0 CELLSPACING=5 WIDTH=100>
<TR>
<TD ALIGN=RIGHT>";
if (
$offset>=$limit) {
$newoff=$offset-$limit;
echo "<A HREF="$PHP_SELF?offset=$newoff&where=$safewhere">
<-- PREV</A>
</TD>";
} else {
echo "<-- PREV";
}
echo
"<TD ALIGN=CENTER> ";
for (
$i=1;$i<=$numpage;$i++) {
if ((($i-1)*$limit)==$offset) {
print "$i ";
} else {
$newoff=($i-1)*$limit;
echo
"<A HREF="$PHP_SELF?offset=$newoff&where=$safewhere">
$i</A> ";
}
}
echo " </TD>
<TD ALIGN=LEFT>";
if ($offset!=$limit*($numpage-1)) {
$newoff=$offset+$limit;
echo "<A HREF="$PHP_SELF?offset=$newoff&where=$safewhere">
NEXT--></A>
</TD>";
}else{
echo "NEXT--></TD>";
}
echo "</TR>
</TABLE>";
}
// END FUNCTION
// set this to the number of results you wish on each page
$limit=20;
// if no offset has been passed, offset should be 0
if (!$offset) $offset=0;
if (!
$where) {
if (empty($one) || empty($two)) {
// some error handling as $one and/or
//$two not passed to initial page
}
$where="$one|$two";
}
// NOTE: if a pipe (|) may be in the value
// of $one or $two, use a different delimiter
$data=explode('|',$where);
$query_where="where one='$data[0]' AND two='$data[1]'";
$result=mysql_query("select count(*) from tablename $query_where");
list(
$numrec)=mysql_fetch_row($result);
#calc num pages
$numpage=intval($numrec/$limit);
if (
$numrec%$limit) {
$numpage++; // add one page if remainder
}
$result=mysql_query ("select * from tablename $query_where limit $offset,$limit");
//<!-- HTML headers and other non-relevent stuff -->
if ($numpage>1) {
pagenav();
print "<P>";
}
//<!-- result display loop -->
if ($numpage>1) {
pagenav();
print "<P>";
}
?>
Happy coding.
Rod K