close ad
Help us test the new Databridge BETA with MySQLi support
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Search 'phrase' through Managed Relational Table

Thread began 4/19/2013 11:32 am by paul386190 | Last modified 5/07/2013 11:31 am by paul386190 | 1633 views | 19 replies

paul386190

Search 'phrase' through Managed Relational Table

Hi there, I wonder if anyone can assist. I'm creating a free text search (a single text-input named 'search-keywords') on a website for narrowing down a huge range of products, using the DataAssist Search feature.

The database has three tables:
1. Products: includes product_id, product_name, other product details
2. Keywords: incorporates keywords_id and keywords_name
3. KeywordProduct: incorporates KeywordProduct.KeywordProductID, KeywordProduct.KeywordProductProductID and KeywordProduct.KeywordProductKeywordID

Table 3 is a managed relational table so that a product can be assigned multiple keywords.
The products we have on the site include iPhone 3, iPhone 4, iPhone 5, iPad 2 and iPad 3 so we've opted to use keywords in the style of 'iPhone', 'iPad', '3', '4', '5', rather than complete model numbers as it will be easier when future models are brought out.
The struggle I'm having with the search is when more than one word is entered into the field. So if I search 'iPhone' I get all the products which have 'iPhone' assigned to them and if I search '5' I get all the products which have '5' assigned to them, but if I search 'iPhone 5' I get no results. What we need to happen in this instance is to get all products that have BOTH keywords assigned to them, not just either of them. I've tried a comination of 'include', '=', space for KEYWORD AND, and adding "" around the search term, but to no avail.

This is the code I currently have for the search...

<?php
//WA Database Search (Copyright 2005, WebAssist.com)
//Recordset: rsproducts;
//Searchpage: ;
//Form: ;
$WADbSearch1_DefaultWhere = "";
if (!session_id()) session_start();
if (isset($_POST["search_submit"]) || isset($_POST["search_submit_x"])) {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//keyword array declarations
$KeyArr1 = array("keywords_name");

//comparison list additions
$WADbSearch1->keywordComparison($KeyArr1,"\"".((isset($_POST["search-keywords"]))?$_POST["search-keywords"]:"") ."\"","AND","Includes","%20","OR","%22","%22",0);

//save the query in a session variable
if (1 == 1) {
$_SESSION["WADbSearch1_masthead"]=$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_masthead"]) && $_SESSION["WADbSearch1_masthead"] != "") {
$WADbSearch1->whereClause = $_SESSION["WADbSearch1_masthead"];
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
$WADbSearch1->whereClause = str_replace("\\''", "''", $WADbSearch1->whereClause);
$WADbSearch1whereClause = '';
?>


And this is the query I'm using for gathering the products....

mysql_select_db($database_lazerbuilt, $lazerbuilt);
$query_rsproducts = "SELECT * FROM product, keywords, KeywordProduct WHERE product.product_id = KeywordProduct.KeywordProductProductID and KeywordProduct.KeywordProductKeywordID = keywords.keywords_id";
setQueryBuilderSource($query_rsproducts,$WADbSearch1,false);
$rsproducts = mysql_query($query_rsproducts, $lazerbuilt) or die(mysql_error());
$row_rsproducts = mysql_fetch_assoc($rsproducts);
$totalRows_rsproducts = mysql_num_rows($rsproducts);

I would be very grateful for any assistance.
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...