Forums

PHP

This topic is locked

Advanced Search

Posted 18 Aug 2003 01:35:02
1
has voted
18 Aug 2003 01:35:02 Tim Langford posted:
I purchased and followed the advanced tutorial by Allan Kent but would like to know how I can have the search form and fields on one page (search.php) and then get the results on a different page (prodlisting.php)

Here's my code:

<?php
$maxRows_rs_results = 50;
$pageNum_rs_results = 0;
if (isset($HTTP_GET_VARS['pageNum_rs_results'])) {
$pageNum_rs_results = $HTTP_GET_VARS['pageNum_rs_results'];
}
$startRow_rs_results = $pageNum_rs_results * $maxRows_rs_results;

$colname2_rs_results = "1";
if (isset($HTTP_POST_VARS['txtSubcategory'])) {
$colname2_rs_results = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['txtSubcategory'] : addslashes($HTTP_POST_VARS['txtSubcategory']);
}
$colname3_rs_results = "1";
if (isset($HTTP_POST_VARS['txtSkintype'])) {
$colname3_rs_results = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['txtSkintype'] : addslashes($HTTP_POST_VARS['txtSkintype']);
}
$colname_rs_results = "1";
if (isset($HTTP_POST_VARS['txtBrands'])) {
$colname_rs_results = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['txtBrands'] : addslashes($HTTP_POST_VARS['txtBrands']);
}
mysql_select_db($database_razordicom, $razordicom);
$query_rs_results = sprintf("SELECT title, brand, intro, body, image, category, subcategory, skintype FROM products WHERE brand LIKE '%%%s%%' AND subcategory LIKE '%%%s%%' AND skintype LIKE '%%%s%%'", $colname_rs_results,$colname2_rs_results,$colname3_rs_results);
$query_limit_rs_results = sprintf("%s LIMIT %d, %d", $query_rs_results, $startRow_rs_results, $maxRows_rs_results);
$rs_results = mysql_query($query_limit_rs_results, $razordicom) or die(mysql_error());
$row_rs_results = mysql_fetch_assoc($rs_results);

if (isset($HTTP_GET_VARS['totalRows_rs_results'])) {
$totalRows_rs_results = $HTTP_GET_VARS['totalRows_rs_results'];
} else {
$all_rs_results = mysql_query($query_rs_results);
$totalRows_rs_results = mysql_num_rows($all_rs_results);
}
$totalPages_rs_results = ceil($totalRows_rs_results/$maxRows_rs_results)-1;
?>

This works fine if I only have one criteria in there (eg. brand) if I add any more (AND subcategory) it doesn't work???

EDIT: Just to clarify, the code above does not work unless I remove the subcategory and skintype "AND's"

Can anyone help??




"Give a man a fish and feed him for a day,

Teach him how to fish and feed him for a lifetime..."

Edited by - udude on 18 Aug 2003 01:36:48

Replies

Replied 18 Aug 2003 03:24:50
18 Aug 2003 03:24:50 Tim Langford replied:
OK - I've figured out that nothing was wrong with the results code! The problem is that I have multiple drop down menus in the same form with their default selection as "Select..." So when I submit the form these submit too!

How can I stop these from being submitted? I've made their value nothing and have also tried making their values the same as the default value of the query!

<img src=../images/dmxzone/forum/icon_smile_angry.gif border=0 align=middle>

"Give a man a fish and feed him for a day,

Teach him how to fish and feed him for a lifetime..."

Reply to this topic