Forums
This topic is locked
Search Result Filtered Recordset Navigation
Posted 04 Nov 2006 01:40:37
1
has voted
04 Nov 2006 01:40:37 Anita Wong posted:
Dreamweaver MX 2004/PHPI have a MySQL database and PHP search and results pages. The search filters on multiple fields. If I do a search with no search parameters (all records) the standard navigation bar in Dreamweaver works great in navigating all of the records. I have the repeat region for the results set at 10 records.
If I put in a value to search on (using LIKE in the SQL WHERE query), the initial results page shows the first result page correctly, however, if I click on the next page link, it goes to the 2nd page listing for ALL the records instead of showing the remainder of the filtered records. Then if you click on the previous and next links, they continue to display the full record set.
www.wsdnw.com/WSDPHPTest/search.php is the search page
www.wsdnw.com/WSDPHPTest/searchresults.php is the results page
(values in the "Unit" field go from 1 thru 142, unique values)
It's not passing parameters for the filtered recordset IDs. I don't know PHP so I'm not sure what to modify. Is there a simple solution?
Replies
Replied 06 Nov 2006 13:56:52
06 Nov 2006 13:56:52 Roddy Dairion replied:
first thing you have to do is change the way to pass data from POST to GET. So all you $_POST[] will become $_GET[]. Don't forget to change the method in the form as well.
Replied 06 Nov 2006 23:07:58
06 Nov 2006 23:07:58 Anita Wong replied:
Changing from $_POST to $_GET actually doesn't change much...it in fact, makes it worse in that it doesn't create a filtered recordset for the results page. I need to get the recordset filtered values to pass to the subsequent results pages containing the filtered results. e.g. search for all units with the number 3 in them. There should be 23, but I can only see the first 10, then it goes to the entire recordset for the subsequent pages with the navigation as it is currently coded.
www.wsdnw.com/WSDPHPTest/search_dmx1.php <--- page with $_POST changed to $_GET
www.wsdnw.com/WSDPHPTest/search_dmx1.php <--- page with $_POST changed to $_GET
Replied 07 Nov 2006 10:35:50
07 Nov 2006 10:35:50 Roddy Dairion replied:
Well its a pagination problem. Send the code over.
Replied 07 Nov 2006 18:38:53
07 Nov 2006 18:38:53 Anita Wong replied:
Here's the whole results page w/navigation (search page is just a basic form) :
<?php require_once('Connections/connOwner.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_rsOwners = 10;
$pageNum_rsOwners = 0;
if (isset($_GET['pageNum_rsOwners'])) {
$pageNum_rsOwners = $_GET['pageNum_rsOwners'];
}
$startRow_rsOwners = $pageNum_rsOwners * $maxRows_rsOwners;
$varUnitNo_rsOwners = "%";
if (isset($_POST['UnitNo'])) {
$varUnitNo_rsOwners = (get_magic_quotes_gpc()) ? $_POST['UnitNo'] : addslashes($_POST['UnitNo']);
}
$varName_rsOwners = "%";
if (isset($_POST['Name'])) {
$varName_rsOwners = (get_magic_quotes_gpc()) ? $_POST['Name'] : addslashes($_POST['Name']);
}
$varStreetAddress_rsOwners = "%";
if (isset($_POST['StreetAddress'])) {
$varStreetAddress_rsOwners = (get_magic_quotes_gpc()) ? $_POST['StreetAddress'] : addslashes($_POST['StreetAddress']);
}
mysql_select_db($database_connOwner, $connOwner);
$query_rsOwners = sprintf("SELECT * FROM roster WHERE unit LIKE '%%%s%%' AND owner LIKE '%%%s%%' AND unit_address LIKE '%%%s%%' ORDER BY unit ASC ", $varUnitNo_rsOwners,$varName_rsOwners,$varStreetAddress_rsOwners);
$query_limit_rsOwners = sprintf("%s LIMIT %d, %d", $query_rsOwners, $startRow_rsOwners, $maxRows_rsOwners);
$rsOwners = mysql_query($query_limit_rsOwners, $connOwner) or die(mysql_error());
$row_rsOwners = mysql_fetch_assoc($rsOwners);
if (isset($_GET['totalRows_rsOwners'])) {
$totalRows_rsOwners = $_GET['totalRows_rsOwners'];
} else {
$all_rsOwners = mysql_query($query_rsOwners);
$totalRows_rsOwners = mysql_num_rows($all_rsOwners);
}
$totalPages_rsOwners = ceil($totalRows_rsOwners/$maxRows_rsOwners)-1;
$queryString_rsOwners = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsOwners" == false &&
stristr($param, "totalRows_rsOwners" == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsOwners = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsOwners = sprintf("&totalRows_rsOwners=%d%s", $totalRows_rsOwners, $queryString_rsOwners);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?php if ($totalRows_rsOwners == 0) { // Show if recordset empty ?>
<p>Sorry, no results match your search criteria. Please try again. </p>
<?php } // Show if recordset empty ?>
<table width="500" border="0" cellspacing="0" cellpadding="5">
<tr valign="top">
<td height="20"><div align="center"><strong>Unit No. </strong></div></td>
<td><strong>Owner/Occupant</strong></td>
</tr>
<?php do { ?>
<tr valign="top">
<td height="38"><div align="center"> <?php echo $row_rsOwners['unit']; ?></div></td>
<td><?php echo $row_rsOwners['owner']; ?><br>
<?php echo $row_rsOwners['unit_address']; ?></td>
</tr>
<?php } while ($row_rsOwners = mysql_fetch_assoc($rsOwners)); ?>
</table>
<p>
<table border="0" width="50%" align="left">
<tr>
<td width="23%" align="center"><?php if ($pageNum_rsOwners > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, 0, $queryString_rsOwners); ?>">First</a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center"><?php if ($pageNum_rsOwners > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, max(0, $pageNum_rsOwners - 1), $queryString_rsOwners); ?>">Previous</a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_rsOwners < $totalPages_rsOwners) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, min($totalPages_rsOwners, $pageNum_rsOwners + 1), $queryString_rsOwners); ?>">Next</a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_rsOwners < $totalPages_rsOwners) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, $totalPages_rsOwners, $queryString_rsOwners); ?>">Last</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
</p>
<p> </p>
<p> </p>
<p>Record <?php echo ($startRow_rsOwners + 1) ?> to <?php echo min($startRow_rsOwners + $maxRows_rsOwners, $totalRows_rsOwners) ?> of <?php echo $totalRows_rsOwners ?> </p>
</body>
</html>
<?php
mysql_free_result($rsOwners);
?>
<?php require_once('Connections/connOwner.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_rsOwners = 10;
$pageNum_rsOwners = 0;
if (isset($_GET['pageNum_rsOwners'])) {
$pageNum_rsOwners = $_GET['pageNum_rsOwners'];
}
$startRow_rsOwners = $pageNum_rsOwners * $maxRows_rsOwners;
$varUnitNo_rsOwners = "%";
if (isset($_POST['UnitNo'])) {
$varUnitNo_rsOwners = (get_magic_quotes_gpc()) ? $_POST['UnitNo'] : addslashes($_POST['UnitNo']);
}
$varName_rsOwners = "%";
if (isset($_POST['Name'])) {
$varName_rsOwners = (get_magic_quotes_gpc()) ? $_POST['Name'] : addslashes($_POST['Name']);
}
$varStreetAddress_rsOwners = "%";
if (isset($_POST['StreetAddress'])) {
$varStreetAddress_rsOwners = (get_magic_quotes_gpc()) ? $_POST['StreetAddress'] : addslashes($_POST['StreetAddress']);
}
mysql_select_db($database_connOwner, $connOwner);
$query_rsOwners = sprintf("SELECT * FROM roster WHERE unit LIKE '%%%s%%' AND owner LIKE '%%%s%%' AND unit_address LIKE '%%%s%%' ORDER BY unit ASC ", $varUnitNo_rsOwners,$varName_rsOwners,$varStreetAddress_rsOwners);
$query_limit_rsOwners = sprintf("%s LIMIT %d, %d", $query_rsOwners, $startRow_rsOwners, $maxRows_rsOwners);
$rsOwners = mysql_query($query_limit_rsOwners, $connOwner) or die(mysql_error());
$row_rsOwners = mysql_fetch_assoc($rsOwners);
if (isset($_GET['totalRows_rsOwners'])) {
$totalRows_rsOwners = $_GET['totalRows_rsOwners'];
} else {
$all_rsOwners = mysql_query($query_rsOwners);
$totalRows_rsOwners = mysql_num_rows($all_rsOwners);
}
$totalPages_rsOwners = ceil($totalRows_rsOwners/$maxRows_rsOwners)-1;
$queryString_rsOwners = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsOwners" == false &&
stristr($param, "totalRows_rsOwners" == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsOwners = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsOwners = sprintf("&totalRows_rsOwners=%d%s", $totalRows_rsOwners, $queryString_rsOwners);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?php if ($totalRows_rsOwners == 0) { // Show if recordset empty ?>
<p>Sorry, no results match your search criteria. Please try again. </p>
<?php } // Show if recordset empty ?>
<table width="500" border="0" cellspacing="0" cellpadding="5">
<tr valign="top">
<td height="20"><div align="center"><strong>Unit No. </strong></div></td>
<td><strong>Owner/Occupant</strong></td>
</tr>
<?php do { ?>
<tr valign="top">
<td height="38"><div align="center"> <?php echo $row_rsOwners['unit']; ?></div></td>
<td><?php echo $row_rsOwners['owner']; ?><br>
<?php echo $row_rsOwners['unit_address']; ?></td>
</tr>
<?php } while ($row_rsOwners = mysql_fetch_assoc($rsOwners)); ?>
</table>
<p>
<table border="0" width="50%" align="left">
<tr>
<td width="23%" align="center"><?php if ($pageNum_rsOwners > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, 0, $queryString_rsOwners); ?>">First</a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center"><?php if ($pageNum_rsOwners > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, max(0, $pageNum_rsOwners - 1), $queryString_rsOwners); ?>">Previous</a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_rsOwners < $totalPages_rsOwners) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, min($totalPages_rsOwners, $pageNum_rsOwners + 1), $queryString_rsOwners); ?>">Next</a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_rsOwners < $totalPages_rsOwners) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, $totalPages_rsOwners, $queryString_rsOwners); ?>">Last</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
</p>
<p> </p>
<p> </p>
<p>Record <?php echo ($startRow_rsOwners + 1) ?> to <?php echo min($startRow_rsOwners + $maxRows_rsOwners, $totalRows_rsOwners) ?> of <?php echo $totalRows_rsOwners ?> </p>
</body>
</html>
<?php
mysql_free_result($rsOwners);
?>
Replied 19 Jan 2007 11:01:34
19 Jan 2007 11:01:34 Roddy Dairion replied:
Sorry i took so long. Try this out.
<pre id=code><font face=courier size=2 id=code>
<?php require_once('Connections/connOwner.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_rsOwners = 10;
$pageNum_rsOwners = 0;
if (isset($_GET['pageNum_rsOwners'])) {
$pageNum_rsOwners = $_GET['pageNum_rsOwners'];
}
$startRow_rsOwners = $pageNum_rsOwners * $maxRows_rsOwners;
$varUnitNo_rsOwners = "%";
if (isset($_POST['UnitNo'])) {
$varUnitNo_rsOwners = (get_magic_quotes_gpc()) ? $_POST['UnitNo'] : addslashes($_POST['UnitNo']);
}
$varName_rsOwners = "%";
if (isset($_POST['Name'])) {
$varName_rsOwners = (get_magic_quotes_gpc()) ? $_POST['Name'] : addslashes($_POST['Name']);
}
$varStreetAddress_rsOwners = "%";
if (isset($_POST['StreetAddress'])) {
$varStreetAddress_rsOwners = (get_magic_quotes_gpc()) ? $_POST['StreetAddress'] : addslashes($_POST['StreetAddress']);
}
mysql_select_db($database_connOwner, $connOwner);
$query_rsOwners = "SELECT * FROM roster";
if (isset($_POST['UnitNo']) || isset($_POST['Name']) || isset($_POST['StreetAddress']))
{
$query_reOwners.= "WHERE";
}
if (isset($_POST['UnitNo'])){
$query_reOwners.= "unit LIKE '$varUnitNo_rsOwners'";
}
$query_reOwners.=isset($_POST['UnitNo']) ? 'AND' : '';
if (isset($_POST['Name'])){
$query_reOwners.="owner LIKE '$varName_rsOwners'";
}
$query_reOwners.=isset($_POST['Name']) ? 'AND' : '';
if (isset($_POST['StreetAddress'])){
$query_reOwners.="unit_address LIKE '$varStreetAddress_rsOwners'";
}
$query_reOwners.="ORDER BY unit ASC ";
$query_limit_rsOwners = sprintf("%s LIMIT %d, %d", $query_rsOwners, $startRow_rsOwners, $maxRows_rsOwners);
$rsOwners = mysql_query($query_limit_rsOwners, $connOwner) or die(mysql_error());
$row_rsOwners = mysql_fetch_assoc($rsOwners);
if (isset($_GET['totalRows_rsOwners'])) {
$totalRows_rsOwners = $_GET['totalRows_rsOwners'];
} else {
$all_rsOwners = mysql_query($query_rsOwners);
$totalRows_rsOwners = mysql_num_rows($all_rsOwners);
}
$totalPages_rsOwners = ceil($totalRows_rsOwners/$maxRows_rsOwners)-1;
$queryString_rsOwners = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsOwners" == false &&
stristr($param, "totalRows_rsOwners" == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsOwners = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsOwners = sprintf("&totalRows_rsOwners=%d%s", $totalRows_rsOwners, $queryString_rsOwners);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?php if ($totalRows_rsOwners == 0) { // Show if recordset empty ?>
<p>Sorry, no results match your search criteria. Please try again. </p>
<?php } // Show if recordset empty ?>
<table width="500" border="0" cellspacing="0" cellpadding="5">
<tr valign="top">
<td height="20"><div align="center"><strong>Unit No. </strong></div></td>
<td><strong>Owner/Occupant</strong></td>
</tr>
<?php do { ?>
<tr valign="top">
<td height="38"><div align="center"> <?php echo $row_rsOwners['unit']; ?></div></td>
<td><?php echo $row_rsOwners['owner']; ?><br>
<?php echo $row_rsOwners['unit_address']; ?></td>
</tr>
<?php } while ($row_rsOwners = mysql_fetch_assoc($rsOwners)); ?>
</table>
<p>
<table border="0" width="50%" align="left">
<tr>
<td width="23%" align="center"><?php if ($pageNum_rsOwners > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, 0, $queryString_rsOwners); ?>">First</a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center"><?php if ($pageNum_rsOwners > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, max(0, $pageNum_rsOwners - 1), $queryString_rsOwners); ?>">Previous</a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_rsOwners < $totalPages_rsOwners) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, min($totalPages_rsOwners, $pageNum_rsOwners + 1), $queryString_rsOwners); ?>">Next</a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_rsOwners < $totalPages_rsOwners) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, $totalPages_rsOwners, $queryString_rsOwners); ?>">Last</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
</p>
<p> </p>
<p> </p>
<p>Record <?php echo ($startRow_rsOwners + 1) ?> to <?php echo min($startRow_rsOwners + $maxRows_rsOwners, $totalRows_rsOwners) ?> of <?php echo $totalRows_rsOwners ?> </p>
</body>
</html>
<?php
mysql_free_result($rsOwners);
?>
</font id=code></pre id=code>
<pre id=code><font face=courier size=2 id=code>
<?php require_once('Connections/connOwner.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_rsOwners = 10;
$pageNum_rsOwners = 0;
if (isset($_GET['pageNum_rsOwners'])) {
$pageNum_rsOwners = $_GET['pageNum_rsOwners'];
}
$startRow_rsOwners = $pageNum_rsOwners * $maxRows_rsOwners;
$varUnitNo_rsOwners = "%";
if (isset($_POST['UnitNo'])) {
$varUnitNo_rsOwners = (get_magic_quotes_gpc()) ? $_POST['UnitNo'] : addslashes($_POST['UnitNo']);
}
$varName_rsOwners = "%";
if (isset($_POST['Name'])) {
$varName_rsOwners = (get_magic_quotes_gpc()) ? $_POST['Name'] : addslashes($_POST['Name']);
}
$varStreetAddress_rsOwners = "%";
if (isset($_POST['StreetAddress'])) {
$varStreetAddress_rsOwners = (get_magic_quotes_gpc()) ? $_POST['StreetAddress'] : addslashes($_POST['StreetAddress']);
}
mysql_select_db($database_connOwner, $connOwner);
$query_rsOwners = "SELECT * FROM roster";
if (isset($_POST['UnitNo']) || isset($_POST['Name']) || isset($_POST['StreetAddress']))
{
$query_reOwners.= "WHERE";
}
if (isset($_POST['UnitNo'])){
$query_reOwners.= "unit LIKE '$varUnitNo_rsOwners'";
}
$query_reOwners.=isset($_POST['UnitNo']) ? 'AND' : '';
if (isset($_POST['Name'])){
$query_reOwners.="owner LIKE '$varName_rsOwners'";
}
$query_reOwners.=isset($_POST['Name']) ? 'AND' : '';
if (isset($_POST['StreetAddress'])){
$query_reOwners.="unit_address LIKE '$varStreetAddress_rsOwners'";
}
$query_reOwners.="ORDER BY unit ASC ";
$query_limit_rsOwners = sprintf("%s LIMIT %d, %d", $query_rsOwners, $startRow_rsOwners, $maxRows_rsOwners);
$rsOwners = mysql_query($query_limit_rsOwners, $connOwner) or die(mysql_error());
$row_rsOwners = mysql_fetch_assoc($rsOwners);
if (isset($_GET['totalRows_rsOwners'])) {
$totalRows_rsOwners = $_GET['totalRows_rsOwners'];
} else {
$all_rsOwners = mysql_query($query_rsOwners);
$totalRows_rsOwners = mysql_num_rows($all_rsOwners);
}
$totalPages_rsOwners = ceil($totalRows_rsOwners/$maxRows_rsOwners)-1;
$queryString_rsOwners = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsOwners" == false &&
stristr($param, "totalRows_rsOwners" == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsOwners = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsOwners = sprintf("&totalRows_rsOwners=%d%s", $totalRows_rsOwners, $queryString_rsOwners);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?php if ($totalRows_rsOwners == 0) { // Show if recordset empty ?>
<p>Sorry, no results match your search criteria. Please try again. </p>
<?php } // Show if recordset empty ?>
<table width="500" border="0" cellspacing="0" cellpadding="5">
<tr valign="top">
<td height="20"><div align="center"><strong>Unit No. </strong></div></td>
<td><strong>Owner/Occupant</strong></td>
</tr>
<?php do { ?>
<tr valign="top">
<td height="38"><div align="center"> <?php echo $row_rsOwners['unit']; ?></div></td>
<td><?php echo $row_rsOwners['owner']; ?><br>
<?php echo $row_rsOwners['unit_address']; ?></td>
</tr>
<?php } while ($row_rsOwners = mysql_fetch_assoc($rsOwners)); ?>
</table>
<p>
<table border="0" width="50%" align="left">
<tr>
<td width="23%" align="center"><?php if ($pageNum_rsOwners > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, 0, $queryString_rsOwners); ?>">First</a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center"><?php if ($pageNum_rsOwners > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, max(0, $pageNum_rsOwners - 1), $queryString_rsOwners); ?>">Previous</a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_rsOwners < $totalPages_rsOwners) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, min($totalPages_rsOwners, $pageNum_rsOwners + 1), $queryString_rsOwners); ?>">Next</a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_rsOwners < $totalPages_rsOwners) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, $totalPages_rsOwners, $queryString_rsOwners); ?>">Last</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
</p>
<p> </p>
<p> </p>
<p>Record <?php echo ($startRow_rsOwners + 1) ?> to <?php echo min($startRow_rsOwners + $maxRows_rsOwners, $totalRows_rsOwners) ?> of <?php echo $totalRows_rsOwners ?> </p>
</body>
</html>
<?php
mysql_free_result($rsOwners);
?>
</font id=code></pre id=code>
Replied 20 Jan 2007 02:29:01
20 Jan 2007 02:29:01 Anita Wong replied:
Nope...this method doesn't have any filtering capability. It finds the entire recordset. See www.wsdnw.com/WSDPHPTest/search_dmx1.php
Result page is the code you provided above.
I would like it to filter by any one of the fields, e.g. if I enter "5 in the Unit No. field, I get only the units with the number 5 in them (5, 15, 25, 35, 45, 50, 51, 52, 53, 54) and then be able to navigate to the next page with the next set of 10 records which have the number 5 in them (55, 56, 57, 58, 59, 65, 75, 85, 95, 105) and so on. What happens is I get the first 10 filtered and then upon clicking on the navigation button, the filter is no longer valid and I get all of the records, not just the ones with 5 in them.
Thanks again for looking into this.
Result page is the code you provided above.
I would like it to filter by any one of the fields, e.g. if I enter "5 in the Unit No. field, I get only the units with the number 5 in them (5, 15, 25, 35, 45, 50, 51, 52, 53, 54) and then be able to navigate to the next page with the next set of 10 records which have the number 5 in them (55, 56, 57, 58, 59, 65, 75, 85, 95, 105) and so on. What happens is I get the first 10 filtered and then upon clicking on the navigation button, the filter is no longer valid and I get all of the records, not just the ones with 5 in them.
Thanks again for looking into this.
Replied 22 Jan 2007 15:04:23
22 Jan 2007 15:04:23 Roddy Dairion replied:
my bad Anita huge typing mistake. Try this new one. Thx
<pre id=code><font face=courier size=2 id=code>
<?php require_once('Connections/connOwner.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_rsOwners = 10;
$pageNum_rsOwners = 0;
if (isset($_GET['pageNum_rsOwners'])) {
$pageNum_rsOwners = $_GET['pageNum_rsOwners'];
}
$startRow_rsOwners = $pageNum_rsOwners * $maxRows_rsOwners;
$varUnitNo_rsOwners = "%";
if (isset($_POST['UnitNo'])) {
$varUnitNo_rsOwners = (get_magic_quotes_gpc()) ? $_POST['UnitNo'] : addslashes($_POST['UnitNo']);
}
$varName_rsOwners = "%";
if (isset($_POST['Name'])) {
$varName_rsOwners = (get_magic_quotes_gpc()) ? $_POST['Name'] : addslashes($_POST['Name']);
}
$varStreetAddress_rsOwners = "%";
if (isset($_POST['StreetAddress'])) {
$varStreetAddress_rsOwners = (get_magic_quotes_gpc()) ? $_POST['StreetAddress'] : addslashes($_POST['StreetAddress']);
}
mysql_select_db($database_connOwner, $connOwner);
$query_rsOwners = "SELECT * FROM roster";
if (isset($_POST['UnitNo']) || isset($_POST['Name']) || isset($_POST['StreetAddress']))
{
$query_rsOwners.= "WHERE";
}
if (isset($_POST['UnitNo'])){
$query_rsOwners.= "unit LIKE '$varUnitNo_rsOwners'";
}
$query_rsOwners.=isset($_POST['UnitNo']) ? 'AND' : '';
if (isset($_POST['Name'])){
$query_rsOwners.="owner LIKE '$varName_rsOwners'";
}
$query_rsOwners.=isset($_POST['Name']) ? 'AND' : '';
if (isset($_POST['StreetAddress'])){
$query_rsOwners.="unit_address LIKE '$varStreetAddress_rsOwners'";
}
$query_rsOwners.="ORDER BY unit ASC ";
$query_limit_rsOwners = sprintf("%s LIMIT %d, %d", $query_rsOwners, $startRow_rsOwners, $maxRows_rsOwners);
$rsOwners = mysql_query($query_limit_rsOwners, $connOwner) or die(mysql_error());
$row_rsOwners = mysql_fetch_assoc($rsOwners);
if (isset($_GET['totalRows_rsOwners'])) {
$totalRows_rsOwners = $_GET['totalRows_rsOwners'];
} else {
$all_rsOwners = mysql_query($query_rsOwners);
$totalRows_rsOwners = mysql_num_rows($all_rsOwners);
}
$totalPages_rsOwners = ceil($totalRows_rsOwners/$maxRows_rsOwners)-1;
$queryString_rsOwners = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsOwners" == false &&
stristr($param, "totalRows_rsOwners" == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsOwners = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsOwners = sprintf("&totalRows_rsOwners=%d%s", $totalRows_rsOwners, $queryString_rsOwners);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?php if ($totalRows_rsOwners == 0) { // Show if recordset empty ?>
<p>Sorry, no results match your search criteria. Please try again. </p>
<?php } // Show if recordset empty ?>
<table width="500" border="0" cellspacing="0" cellpadding="5">
<tr valign="top">
<td height="20"><div align="center"><strong>Unit No. </strong></div></td>
<td><strong>Owner/Occupant</strong></td>
</tr>
<?php do { ?>
<tr valign="top">
<td height="38"><div align="center"> <?php echo $row_rsOwners['unit']; ?></div></td>
<td><?php echo $row_rsOwners['owner']; ?><br>
<?php echo $row_rsOwners['unit_address']; ?></td>
</tr>
<?php } while ($row_rsOwners = mysql_fetch_assoc($rsOwners)); ?>
</table>
<p>
<table border="0" width="50%" align="left">
<tr>
<td width="23%" align="center"><?php if ($pageNum_rsOwners > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, 0, $queryString_rsOwners); ?>">First</a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center"><?php if ($pageNum_rsOwners > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, max(0, $pageNum_rsOwners - 1), $queryString_rsOwners); ?>">Previous</a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_rsOwners < $totalPages_rsOwners) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, min($totalPages_rsOwners, $pageNum_rsOwners + 1), $queryString_rsOwners); ?>">Next</a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_rsOwners < $totalPages_rsOwners) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, $totalPages_rsOwners, $queryString_rsOwners); ?>">Last</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
</p>
<p> </p>
<p> </p>
<p>Record <?php echo ($startRow_rsOwners + 1) ?> to <?php echo min($startRow_rsOwners + $maxRows_rsOwners, $totalRows_rsOwners) ?> of <?php echo $totalRows_rsOwners ?> </p>
</body>
</html>
<?php
mysql_free_result($rsOwners);
?>
</font id=code></pre id=code>
Edited by - roders22 on 22 Jan 2007 15:04:55
<pre id=code><font face=courier size=2 id=code>
<?php require_once('Connections/connOwner.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_rsOwners = 10;
$pageNum_rsOwners = 0;
if (isset($_GET['pageNum_rsOwners'])) {
$pageNum_rsOwners = $_GET['pageNum_rsOwners'];
}
$startRow_rsOwners = $pageNum_rsOwners * $maxRows_rsOwners;
$varUnitNo_rsOwners = "%";
if (isset($_POST['UnitNo'])) {
$varUnitNo_rsOwners = (get_magic_quotes_gpc()) ? $_POST['UnitNo'] : addslashes($_POST['UnitNo']);
}
$varName_rsOwners = "%";
if (isset($_POST['Name'])) {
$varName_rsOwners = (get_magic_quotes_gpc()) ? $_POST['Name'] : addslashes($_POST['Name']);
}
$varStreetAddress_rsOwners = "%";
if (isset($_POST['StreetAddress'])) {
$varStreetAddress_rsOwners = (get_magic_quotes_gpc()) ? $_POST['StreetAddress'] : addslashes($_POST['StreetAddress']);
}
mysql_select_db($database_connOwner, $connOwner);
$query_rsOwners = "SELECT * FROM roster";
if (isset($_POST['UnitNo']) || isset($_POST['Name']) || isset($_POST['StreetAddress']))
{
$query_rsOwners.= "WHERE";
}
if (isset($_POST['UnitNo'])){
$query_rsOwners.= "unit LIKE '$varUnitNo_rsOwners'";
}
$query_rsOwners.=isset($_POST['UnitNo']) ? 'AND' : '';
if (isset($_POST['Name'])){
$query_rsOwners.="owner LIKE '$varName_rsOwners'";
}
$query_rsOwners.=isset($_POST['Name']) ? 'AND' : '';
if (isset($_POST['StreetAddress'])){
$query_rsOwners.="unit_address LIKE '$varStreetAddress_rsOwners'";
}
$query_rsOwners.="ORDER BY unit ASC ";
$query_limit_rsOwners = sprintf("%s LIMIT %d, %d", $query_rsOwners, $startRow_rsOwners, $maxRows_rsOwners);
$rsOwners = mysql_query($query_limit_rsOwners, $connOwner) or die(mysql_error());
$row_rsOwners = mysql_fetch_assoc($rsOwners);
if (isset($_GET['totalRows_rsOwners'])) {
$totalRows_rsOwners = $_GET['totalRows_rsOwners'];
} else {
$all_rsOwners = mysql_query($query_rsOwners);
$totalRows_rsOwners = mysql_num_rows($all_rsOwners);
}
$totalPages_rsOwners = ceil($totalRows_rsOwners/$maxRows_rsOwners)-1;
$queryString_rsOwners = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsOwners" == false &&
stristr($param, "totalRows_rsOwners" == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsOwners = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsOwners = sprintf("&totalRows_rsOwners=%d%s", $totalRows_rsOwners, $queryString_rsOwners);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?php if ($totalRows_rsOwners == 0) { // Show if recordset empty ?>
<p>Sorry, no results match your search criteria. Please try again. </p>
<?php } // Show if recordset empty ?>
<table width="500" border="0" cellspacing="0" cellpadding="5">
<tr valign="top">
<td height="20"><div align="center"><strong>Unit No. </strong></div></td>
<td><strong>Owner/Occupant</strong></td>
</tr>
<?php do { ?>
<tr valign="top">
<td height="38"><div align="center"> <?php echo $row_rsOwners['unit']; ?></div></td>
<td><?php echo $row_rsOwners['owner']; ?><br>
<?php echo $row_rsOwners['unit_address']; ?></td>
</tr>
<?php } while ($row_rsOwners = mysql_fetch_assoc($rsOwners)); ?>
</table>
<p>
<table border="0" width="50%" align="left">
<tr>
<td width="23%" align="center"><?php if ($pageNum_rsOwners > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, 0, $queryString_rsOwners); ?>">First</a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center"><?php if ($pageNum_rsOwners > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, max(0, $pageNum_rsOwners - 1), $queryString_rsOwners); ?>">Previous</a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_rsOwners < $totalPages_rsOwners) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, min($totalPages_rsOwners, $pageNum_rsOwners + 1), $queryString_rsOwners); ?>">Next</a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_rsOwners < $totalPages_rsOwners) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsOwners=%d%s", $currentPage, $totalPages_rsOwners, $queryString_rsOwners); ?>">Last</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
</p>
<p> </p>
<p> </p>
<p>Record <?php echo ($startRow_rsOwners + 1) ?> to <?php echo min($startRow_rsOwners + $maxRows_rsOwners, $totalRows_rsOwners) ?> of <?php echo $totalRows_rsOwners ?> </p>
</body>
</html>
<?php
mysql_free_result($rsOwners);
?>
</font id=code></pre id=code>
Edited by - roders22 on 22 Jan 2007 15:04:55