I have a simple database driven search engine that work great. I have added pagination to it and am have problems with the results that are returned. When I do a search and set the number of results per page I want through the search form, the first page of results are correct. When I click "Next Page" to see more results it shows all records in the database stating with what would be the second page of that listing.
Im not sure if I have explained enough or very clearly. I will post code below, please reply with any questions and I will try to give a better desciption of what is happening.
Search Page:
<html>
<head>
<title>Search Engine</title>
</head>
</body>
Search:
<form method="post" action="site_results.php">
<input type="text" name="search" size=25 maxlength=100><input type="Submit" name="Submit" value="Search">
<br>
Number of results per page.
<select name="numresults[]" size="1">
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
</select>
</form>
</body>
</html>
Results Page:
<html>
<head>
<title>Search Engine</title>
</head>
</body>
Search:
<form method="post" action="<? echo ($_SERVER[PHP_SELF]);?>">
<input type="text" name="search" value="<? echo $search; ?>" size=25 maxlength=100>
<select name="numresults[]" size="1">
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
</select>
<input type="Submit" name="Submit" value="Search">
</form>
<! Start of search engine code.>
<?
mysql_pconnect("localhost","user","pass");
mysql_select_db("search");
$search=$_POST["search"];
$numresults2=$_POST["numresults"];
$count=count($numresults2);
for ($i=0; $i<$count; $i++){
$numresults= $numresults2[$i];
}
if(!$rowstart) $rowstart=0;
$result = mysql_query("select * from search WHERE about Like '%$search%' OR title LIKE '%$search%'limit $rowstart,$numresults");
$result2 = mysql_query("select * from search WHERE about Like '%$search%' OR title LIKE '%$search%'");
$result3 = $result2;
$numrows2=mysql_num_rows($result3);
echo "<font color=red>Your search returned $numrows2 results.</font>";
echo "<br>";
echo "<br>";
if($row = mysql_fetch_array($result)){
do{
printf("<b><a href=%s>%s</a></b><br>", $row['Link'], $row['Title']);
echo $row['About'];
echo "<br>";
echo "<font color=#CCCCCC>";
echo $row['Link'];
echo "</font>";
echo "<br>";
echo "<br>";
}while($row = mysql_fetch_array($result));
{
$name=$row['About'];
echo $name;
echo "<br>";
}
} else {
echo "No Records Found!";
}
if ($rowstart>$numrows)
{?>
<A HREF="<? $php_self ?>?rowstart=<? echo $rowstart-$numresults;?>&numresults=<? echo $numresults;?>&search=<? echo $search;?>">
< Previous Page</A>
<?}?>
<?
$numrows=mysql_num_rows($result2);
if($rowstart+$numresults<$numrows)
{?>
| <A HREF="<? $php_self?>?rowstart=<? echo $rowstart+$numresults;?>&numresults=<? echo $numresults;?>&search=<? echo $search;?>">
Next Page ></A>
<? } ?>
<! End of Search Engine Code>
</body>
</html>
Thanks in advance for any help!