close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Multi-checkbox search facility

Thread began 2/22/2016 9:51 am by paul386190 | Last modified 2/23/2016 2:27 pm by Ray Borduin | 2062 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.

Sign in to reply to this post

Ray BorduinWebAssist

Try updating the search references to add the table reference to the column like:

$WADbSearch1->addComparisonFromList("product.brand_id","brand","AND","=",1);
$WADbSearch1->addComparisonFromList("product.product_type_id","product_type","AND","=",1);

Sign in to reply to this post
Did this help? Tips are appreciated...

paul386190

Thanks for the swift response Ray. That's now displaying the page, but the search doesn't appear to work yet. Any thoughts on what I may be missing?

Sign in to reply to this post

Ray BorduinWebAssist

Do you have a URL where I can see what you are trying? I can maybe spot the problem that way.

Sign in to reply to this post
Did this help? Tips are appreciated...

paul386190

Hi Ray, I've added the details in the pm.

Sign in to reply to this post

Ray BorduinWebAssist

It looks like it would work to me. I'll need FTP access to debug it further. Would that be possible?

Sign in to reply to this post
Did this help? Tips are appreciated...

paul386190

Hi Ray, It's currently running on my client's server so I'd need to set you up with FTP access to just that folder. Unfortunately their hosting access details aren't working at the moment and I'm in the UK so I'll need to check with the client first thing in the morning and get back to you if that's okay?

Sign in to reply to this post

Ray BorduinWebAssist

This post has been deleted.


Did this help? Tips are appreciated...

paul386190

Hi Ray, message in pm.

Sign in to reply to this post

Ray BorduinWebAssist

Your page is set up and working properly. The only issue is that it has: WHERE product.product_active = 'Y', and none of the products in your table have 'Y' in the product_active field. If you remove that, then the page search seems to work properly.

Sign in to reply to this post
Did this help? Tips are appreciated...
loading

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...