- Impact
- 0
Hi there,
I'm trying to create a simple search engine for a client so that customers can search his products. I have one field for text, and another with a drop down list of product types and an "All Items" option.
I've got my recordset to display search results matching the text field and the products, but I can't get it to display All Items if the customer selects that! So basically they can search by product type, but not across all the products.
I'm doing this in Dreamweaver. My actual PHP coding knowledge is...terrible!
Here is my code:
<?php
$colname2_products = "-1";
if (isset($_POST['type'])) {
$colname2_products = (get_magic_quotes_gpc()) ? $_POST['type'] : addslashes($_POST['type']);
}
$colname_products = "-1";
if (isset($_POST['searchterm'])) {
$colname_products = (get_magic_quotes_gpc()) ? $_POST['searchterm'] : addslashes($_POST['searchterm']);
}
mysql_select_db($database_kofightposters, $kofightposters);
$query_products = sprintf("SELECT * FROM products WHERE name LIKE '%%%s%%' AND type = '%s' ORDER BY name ASC ", $colname_products,$colname2_products);
$products = mysql_query($query_products, $kofightposters) or die(mysql_error());
$row_products = mysql_fetch_assoc($products);
$totalRows_products = mysql_num_rows($products);
?>
Any help would be greatly appreciated!
Cheers,
Rich
I'm trying to create a simple search engine for a client so that customers can search his products. I have one field for text, and another with a drop down list of product types and an "All Items" option.
I've got my recordset to display search results matching the text field and the products, but I can't get it to display All Items if the customer selects that! So basically they can search by product type, but not across all the products.
I'm doing this in Dreamweaver. My actual PHP coding knowledge is...terrible!
Here is my code:
<?php
$colname2_products = "-1";
if (isset($_POST['type'])) {
$colname2_products = (get_magic_quotes_gpc()) ? $_POST['type'] : addslashes($_POST['type']);
}
$colname_products = "-1";
if (isset($_POST['searchterm'])) {
$colname_products = (get_magic_quotes_gpc()) ? $_POST['searchterm'] : addslashes($_POST['searchterm']);
}
mysql_select_db($database_kofightposters, $kofightposters);
$query_products = sprintf("SELECT * FROM products WHERE name LIKE '%%%s%%' AND type = '%s' ORDER BY name ASC ", $colname_products,$colname2_products);
$products = mysql_query($query_products, $kofightposters) or die(mysql_error());
$row_products = mysql_fetch_assoc($products);
$totalRows_products = mysql_num_rows($products);
?>
Any help would be greatly appreciated!
Cheers,
Rich






