Any ideas to the problem with the following?
Despite limiting rows to 2, entire results are output on one page. Any ideas gratefully received.
Rob
<?php
if ($location == "")
{$location = '%';}
if ($price == "")
{$price = '%';}
$limit= 2; // rows to return
$numresults=mysql_query("SELECT * FROM properties
WHERE location LIKE '$location%'
AND price <= '$price%'
");
$numrows=mysql_num_rows($numresults);
// next determine if offset has been passed to script, if not use 0
if (empty($offset)) {
$offset=0;
}
// get results
$result=mysql_query("SELECT * FROM properties
WHERE location LIKE '$location%'
AND price <= '$price%'");
// now you can display the results returned
if ($row = mysql_fetch_array($result)) {
do {
echo("<table width=500 bgcolor=#C0FFFF cellpadding=5><tr><td>");
print $row["description"]; echo("</td></tr>");
print (" ");
echo("<tr><td><b>"); print $row["location"]; echo("</b></td>");
print (" ");
echo("<td>"); print $row["auctioneer"]; echo("</td>");
print (" ");
echo("<td align=right>"); print $row["price"]; echo("</td></tr></table>");
print ("<p>");
} while($row = mysql_fetch_array($result));
} else {print "Sorry, no records were found!";}
// include code to display results as you see fit
// next we need to do the links to other results
if ($offset) { // bypass back link if page is 0
$prevoffset=$offset - $limit;
print "<a href=\"$PHP_SELF?page=$prevoffset\">back</a> <font class=\"small\">-</font> \n";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$limit*($i-1);
print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> \n";
}
// check to see if last page
if (!(($offset/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$newoffset=$offset+$limit;
print "<a href=\"$PHP_SELF?offset=$newoffset\">NEXT</a><p>\n";
}
?>