I've put together a search section for my wine web directory site, but I'm having a problem with breaking it into pages and numbering. the numbering is appearing at the bottom of the results list, but all the results are being returned on the first page, even though there should only be 15.
Site can be found at: http://www.winereader.com/search.php
here's the code I'm using:
// database connection stuff here
include ('dbconnect.inc');
mysql_select_db("winereaderdb",$dbcnx);
$searchstring = explode(", ",$keywords);
sort($searchstring);
$l = count($searchstring);
$rows_per_page = 15;
for ($i = 0; $i < $l ; $i++) {
$sql = "SELECT * FROM sites where description like '%$searchstring[$i]%' or name like '%$searchstring[$i]%' ORDER BY name ASC ";
$result = mysql_query($sql,$dbcnx)
or die("Couldn't execute query.");
}
$total_records = mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
mysql_free_result($result);
if (!isset($screen))
$screen = 0;
$start = $screen * $rows_per_page;
for ($i = 0; $i < $l ; $i++) {
$sql = "SELECT * FROM sites where description like '%$searchstring[$i]%' or name like '%$searchstring[$i]%' ORDER BY name ASC ";
$result = mysql_query($sql,$dbcnx)
or die("Couldn't execute query.");
$sql .= "LIMIT $start, $rows_per_page";
$rows = mysql_num_rows($result);
while ( $row = mysql_fetch_array($result) ) {
$id = $row["id"];
$name = $row["name"];
$url = $row["url"];
$description = $row["description"];
echo ("<p><a href='$url' target='_blank'>$name</a><br>
$description</p>");
}
}
$youhere=$screen+1;
echo "<hr>
You are on page $youhere of $pages.<br>";
// page numbering links now
for ($i = 0; $i < $pages; $i++) {
$url = "searchresults.php?screen=" . $i;
$pagenumber=$i+1;
echo " | <a href=\"$url\">$pagenumber</a> | ";
}