Multi-checkbox search facility
Before I start I have to apologise if this all sounds straightforward. I haven't worked on websites for over a year so this is kind of fresh to me again. I've looked through several other similar posts but I'm struggling to get my head around it all.
I'm creating a search facility, on a page named 'webassist-search.php' so that visitors can narrow down the number of products they see by brand and/or product type using 2 sets of checkboxes (the first set are all named "brand[]" while the second set are all named "product_type[]"). The visitor can then select as many options in each and just see the resulting products. For example, if they select the 'Disney' and 'Marvel' checkboxes within 'Brand' they will see all products that fall into either of these brands. Alternatively, if they select both of these brands and also 'audio' within 'Product Type' they will then just see all products that are 'Disney' & 'Audio' and 'Marvel' & 'Audio'. A product can only be associated to one brand and one product type.
I have three tables:
brand - with brand_id and brand_name columns
product_type - with product_type_id and product_type_name
product - with product_id, brand_id, product_type_id, product_name etc.
I've set up 3 recordsets...
$query_brand = "SELECT * FROM brand WHERE brand_active = 'Y' ORDER BY brand_name ASC"
$query_product_type = "SELECT * FROM product_type WHERE product_type_active = 'Y' ORDER BY product_type_name ASC"
$query_product = "SELECT * FROM product INNER JOIN brand ON product.brand_id = brand.brand_id INNER JOIN product_type ON product.product_type_id = product_type.product_type_id WHERE product.product_active = 'Y' ORDER BY product.product_name ASC"
And this is the code that the DataAssist Search has generated...
<?php
//WA Database Search (Copyright 2005, WebAssist.com)
//Recordset: product;
//Searchpage: ;
//Form: ;
$WADbSearch1_DefaultWhere = "";
if (!session_id()) session_start();
if (isset($_POST["WADbSearch1"]) || isset($_POST["WADbSearch1_x"])) {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//keyword array declarations
//comparison list additions
$WADbSearch1->addComparisonFromList("brand_id","brand","AND","=",1);
$WADbSearch1->addComparisonFromList("product_type_id","product_type","AND","=",1);
//save the query in a session variable
if (1 == 1) {
$_SESSION["WADbSearch1_webassistsearch"]=$WADbSearch1->whereClause;
}
}
else {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//get the filter definition from a session variable
if (1 == 1) {
if (isset($_SESSION["WADbSearch1_webassistsearch"]) && $_SESSION["WADbSearch1_webassistsearch"] != "") {
$WADbSearch1->whereClause = $_SESSION["WADbSearch1_webassistsearch"];
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
$WADbSearch1->whereClause = str_replace("\\''", "''", $WADbSearch1->whereClause);
$WADbSearch1whereClause = '';
?>
And I would like visitors to be taken to the same page for the results so the form action is 'webassist-search.php'. However, at the moment, when I load the page I simply get the message "Column 'brand_id' in where clause is ambiguous". I have also attached the file which may make things a little clearer
Any help would be greatly appreciated.
Many thanks in advance
Paul.