I have found this code on the web to help me add prev/next pages when searching a database. I have had a look through the code, and I can understand what it does and how it does it, but there is no section where it actually connects to the database. Please could you take a look and let me know, cheers.
<?php
// set this to the number of results you wish on each page
$limit=5;
$offset = 0;
// if no offset has been passed, offset should be 0
if (!$offset) {
$offset=0;
}
?>
<?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=5;
// if no offset has been passed, offset should be 0
if (!$offset) $offset=0;
//$query_where="where one='$data[0]' AND two='$data[1]'";
$result=mysql_query("select count(*) from rochdale where price >'0' and price <'200000'"
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 rochdale where price >'0' and price <'200000' 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>";
}
?>
<?php
// set this to the number of results you wish on each page
$limit=5;
$offset = 0;
// if no offset has been passed, offset should be 0
if (!$offset) {
$offset=0;
}
?>
<?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=5;
// if no offset has been passed, offset should be 0
if (!$offset) $offset=0;
//$query_where="where one='$data[0]' AND two='$data[1]'";
$result=mysql_query("select count(*) from rochdale where price >'0' and price <'200000'"
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 rochdale where price >'0' and price <'200000' 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>";
}
?>