Forums
This topic is locked
how can I set filter to result page? php/mysql
Posted 07 Apr 2003 22:23:33
1
has voted
07 Apr 2003 22:23:33 Manou Manou posted:
Hi;Ok,
I did make a simple search page using a text box and a submit button, the search works ( almost), now I need to filter the data, that the right data shows up in result page.
for now now matter what you type in text box or even leave it empty with a click of submit the result page shows all the data,
How can I start to set a filter, to show only related data to what is typed.
thanks for any help,
here is my code of result page:
[php]
<?php require_once('../Connections/conn_friends.php'); ?>
<?php require_once('../Connections/conn_friends.php'); ?>
<?php
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];
$maxRows_rsResult = 10;
$pageNum_rsResult = 0;
if (isset($HTTP_GET_VARS['pageNum_rsResult'])) {
$pageNum_rsResult = $HTTP_GET_VARS['pageNum_rsResult'];
}
$startRow_rsResult = $pageNum_rsResult * $maxRows_rsResult;
mysql_select_db($database_conn_friends, $conn_friends);
$query_rsResult = "SELECT * FROM friends";
$query_limit_rsResult = sprintf("%s LIMIT %d, %d", $query_rsResult, $startRow_rsResult, $maxRows_rsResult);
$rsResult = mysql_query($query_limit_rsResult, $conn_friends) or die(mysql_error());
$row_rsResult = mysql_fetch_assoc($rsResult);
if (isset($HTTP_GET_VARS['totalRows_rsResult'])) {
$totalRows_rsResult = $HTTP_GET_VARS['totalRows_rsResult'];
} else {
$all_rsResult = mysql_query($query_rsResult);
$totalRows_rsResult = mysql_num_rows($all_rsResult);
}
$totalPages_rsResult = ceil($totalRows_rsResult/$maxRows_rsResult)-1;
$queryString_rsResult = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsResult"

stristr($param, "totalRows_rsResult"

array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsResult = "&" . implode("&", $newParams);
}
}
$queryString_rsResult = sprintf("&totalRows_rsResult=%d%s", $totalRows_rsResult, $queryString_rsResult);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="787" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="20" height="56"> </td>
<td width="619"> </td>
<td width="148"> </td>
</tr>
<tr>
<td height="22"> </td>
<td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<?php $count=0; ?>
<?php do { ?>
<?php
$count++;
if(($count %2)==1){
$background="#ffffcc";
}
else{
$background="#ffffff";
} ?>
<tr bgcolor ="<?php echo $background; ?>">
<td width="181" height="22" valign="top"><?php echo $row_rsResult['first_name']; ?></td>
<td width="41"> </td>
<td width="146" valign="top"><?php echo $row_rsResult['last_name']; ?></td>
<td width="123" valign="top"><?php echo $row_rsResult['e_mail']; ?></td>
<td width="127" valign="top"><?php echo $row_rsResult['salary']; ?></td>
</tr>
<?php } while ($row_rsResult = mysql_fetch_assoc($rsResult)); ?>
</table>
</td>
<td> </td>
</tr>
<tr>
<td height="186"></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($rsResult);
?>
[/php]
appreciate your help