Search Results lose filter after first page
Posted: Fri Jan 07, 2011 7:33 pm
Hello again,
I have another problem. I have a search form, which searches for different data (name, street ...) and a results page which outputs the results.
I have already built the pagination and it seems the search finds the CORRECT count of results (e.g. if I search for "Smith" it says it found 39 Smiths in the DB, which is indeed correct), but it only shows all Smiths in the first page (e.g. 15 results) but if I click on "next" it shows unfiltered results (e.g. it shows any results from DB which have nothing to do with the search word "Smith").
It still outputs the correct number of pages and count (e.g. a total of 39 results) but only the first 15 results are "Smith" while all the rest is just a variety of other names from the DB.
Here is the code of the results.php page:
Thank you for your help.
I have another problem. I have a search form, which searches for different data (name, street ...) and a results page which outputs the results.
I have already built the pagination and it seems the search finds the CORRECT count of results (e.g. if I search for "Smith" it says it found 39 Smiths in the DB, which is indeed correct), but it only shows all Smiths in the first page (e.g. 15 results) but if I click on "next" it shows unfiltered results (e.g. it shows any results from DB which have nothing to do with the search word "Smith").
It still outputs the correct number of pages and count (e.g. a total of 39 results) but only the first 15 results are "Smith" while all the rest is just a variety of other names from the DB.
Here is the code of the results.php page:
Code: Select all
$maxRows_Recordset1 = 15;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($database_skajclients, $skajclients);
$query_Recordset1 = "SELECT * FROM users WHERE users.emri LIKE '".$_POST["Keywords"]."%' OR users.rruga LIKE '".$_POST["Keywords"]."%' OR users.mbiemri LIKE '".$_POST["Keywords"]."%' OR users.link_me_kodet LIKE '".$_POST["Keywords"]."%' OR users.karta LIKE '".$_POST["Keywords"]."%' OR users.vendi LIKE '".$_POST["Keywords"]."%'";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $skajclients) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
.... HTML ....
<?php do { ?>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="20%" class="style4"><?php echo $row_Recordset1['emri']; ?></td>
<td width="20%" class="style4"><?php echo $row_Recordset1['mbiemri']; ?></td>
<td width="20%" class="style4"><?php echo $row_Recordset1['vendi']; ?></td>
<td width="20%" class="style4"><?php echo $row_Recordset1['karta']; ?></td>
<td align="right" class="style3"><a href="skaj_clients.php?mod=abonimi&id=<?php echo $row_Recordset1['id']; ?>">Hape>></a></td>
</tr>
<tr>
<td colspan="5"><hr /></td>
</tr>
</table>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
<table border="0" width="50%" align="center">
<tr>
<td width="23%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>"><img src="First.gif" border=0></a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>"><img src="Previous.gif" border=0></a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>"><img src="Next.gif" border=0></a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>"><img src="Last.gif" border=0></a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Thank you for your help.