|
Hello,
I'm trying to build a search results page. I would appreciate it if someone would kindly give me a tip on what might be wrong with this code.
I want this conditional statement to show items on a page based on whether a particular form variable or URL variable exists. If neither variable is set, I want it to show everything.
Problems: It seems as though the existance of the form variable is being ignored as my results page defaults to showing everything when I pass the form variable. On the other hand, when I pass the URL variable, my results page returns no records at all.
Code:
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_All_Items = 10;
$pageNum_All_Items = 0;
if (isset($_GET['pageNum_All_Items'])) {
$pageNum_All_Items = $_GET['pageNum_All_Items'];
}
$startRow_All_Items = $pageNum_All_Items * $maxRows_All_Items;
mysql_select_db($database_Sale, $Sale);
if(isset($_POST['KeyWords'])){
$query_All_Items = sprintf("SELECT * FROM Items WHERE Listing_Title LIKE '%%%s%%' or Description LIKE '%%%s%%' ORDER BY Price ASC", $colname_All_Items,$colname_All_Items);}
else if(isset($_GET['Category'])){
$query_All_Items = sprintf("SELECT * FROM Items WHERE Category = '%s' ORDER BY Price ASC", $colname_All_Items);}
else{
$query_All_Items = "SELECT * FROM Items ORDER BY Price ASC";}
$query_limit_All_Items = sprintf("%s LIMIT %d, %d", $query_All_Items, $startRow_All_Items, $maxRows_All_Items);
$All_Items = mysql_query($query_limit_All_Items, $Sale) or die(mysql_error());
$row_All_Items = mysql_fetch_assoc($All_Items);
if (isset($_GET['totalRows_All_Items'])) {
$totalRows_All_Items = $_GET['totalRows_All_Items'];
} else {
$all_All_Items = mysql_query($query_All_Items);
$totalRows_All_Items = mysql_num_rows($all_All_Items);
}
$totalPages_All_Items = ceil($totalRows_All_Items/$maxRows_All_Items)-1;
$queryString_All_Items = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_All_Items") == false &&
stristr($param, "totalRows_All_Items") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_All_Items = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_All_Items = sprintf("&totalRows_All_Items=%d%s", $totalRows_All_Items, $queryString_All_Items);
Any help would be greatly appreciated.
|