close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Multi-checkbox search facility

Thread began 2/22/2016 9:51 am by paul386190 | Last modified 2/23/2016 2:27 pm by paul386190 | 2070 views | 12 replies

paul386190

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.

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...