close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

How To Create a MultiTable search?

Thread began 5/31/2012 6:24 pm by Peterson Design Studio - jefferis | Last modified 6/04/2012 5:08 pm by Peterson Design Studio - jefferis | 1727 views | 31 replies

neo314

Here is another approach I was actually just working on.

<?php
if ($_GET["display"] == "tags") {
$_GET["searchTags"] = true;
$searchTerm_tagSearch = "-1";
if (isset($params[0])) {
$searchTerm_tagSearch = $params[0];
}
mysql_select_db($database_blog, $blog);
$query_tagSearch = sprintf("SELECT GROUP_CONCAT(blog_tags2posts.idPost SEPARATOR ', ') AS tagSearch FROM blog_tags2Posts INNER JOIN blog_tags ON blog_tags.id = blog_tags2Posts.idTag WHERE blog_tags.tag = %s", GetSQLValueString($searchTerm_tagSearch, "text"));
$tagSearch = mysql_query($query_tagSearch, $blog) or die(mysql_error());
$row_tagSearch = mysql_fetch_assoc($tagSearch);
$totalRows_tagSearch = mysql_num_rows($tagSearch);
$_GET["search"] = $row_tagSearch['tagSearch'];
}
?>
<?php
//WA Database Search (Copyright 2005, WebAssist.com)
//Recordset: blogPosts;
//Searchpage: ;
//Form: ;
$WADbSearch1_DefaultWhere = "";
if (!session_id()) session_start();
if ((isset($_GET['searchTags']) && $_GET['searchTags'] != "")) {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//keyword array declarations

//comparison list additions
$WADbSearch1->addComparisonFromList("id","search","OR","=",1);

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

GROUP_CONCAT is used to "implode" all the idPost values from the relational table. Notice the SEPARATOR has to be assigned ", " because that is the separator WA (notice the space after the comma which is not default for the GROUP_CONCAT function).

Then the WADB search behavior is applied. Since I use the url variable display for multiple purposes, I have to specify a separate trigger variable (STILL WISH WE COULD USE EXPRESSIONS AS TRIGGERS). Then a different variable is used for the list of ID's. The GUI field type in the server behavior is list and the separator is OR.



I also noticed that the help file says if more than one WADB Search behavior is used, a default WHERE clause must be specified. I used this approach twice. Once for tags and another for categories. Since the value of display ensures only one recordset of comma separated id's to pull is created, it is important, in this case, to NOT to specify a default WHERE clause or it doesn't work because you end up with a WHERE clause like: WHERE 0=0 OR ((id = 32) OR (id = 47)) which still pulls all the records.

I don't think this can be used for a natural language search . Can it?

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