close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

How To Create a MultiTable search?

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

Peterson Design Studio - jefferis

How To Create a MultiTable search?

Hi, I am creating an admin area. I want the owner to be able to look up 2 things:
the Dealer information from the user table
and the Order information from the Requests table.

ASFAIK, I have to create 2 separate sets of DataAssist search pages, one for each table, which seems odd and redundant. Is there a way to set up A data search and call up dealer info and their order info in one search or set of pages?

FYI, my orders are only requests for custom designed jewelry, not actual processed orders, so they aren't in cart. The dealer fills out his user ID from the user table and inputs a request which goes into the requests table...
TIA,
Jeff

Sign in to reply to this post

Dave BuchholzBeta Tester

Jefferis,

It can be done but not within the extension interface, it is pretty easy if you are comfortable in code view (which I am sure you are) to add new search items to the code block and then join the 2 respective tables in the query as you would normally.

A couple of gotcha's if you have fields that are named the same in both tables you need to explicitly call them i.e. tbl_name.field rather than just field and you cannot use aliases in the search code block.

This is an example of how the code block would look in one of my admin sections

php:
$WADbSearch1 = new FilterDef;

  $WADbSearch1->initializeQueryBuilder("MYSQL","1");
  //keyword array declarations
  $KeyArr0 = array("tbl_orders.id");
  $KeyArr1 = array("tbl_clients.fname", "tbl_clients.lname", "tbl_orders.shipfname", "tbl_orders.shiplname");
  $KeyArr2 = array("tbl_orderdetails.title");
  $KeyArr3 = array("tbl_orderdetails.details");
  $KeyArr4 = array("tbl_orders.id");
  $KeyArr5 = array("tbl_orderdetails.title");
  $KeyArr6 = array("tbl_orderdetails.title");  
  $KeyArr7 = array("tbl_clients.fname", "tbl_clients.lname");
  $KeyArr8 = array("tbl_clients.email");

  //comparison list additions
  $WADbSearch1->keywordComparison($KeyArr0,"".((isset($_GET["zoom_query"]))?$_GET["zoom_query"]:"")  ."","AND","Includes",",%20","%20","%22","%22",0);
  $WADbSearch1->keywordComparison($KeyArr1,"".((isset($_GET["zoom_query"]))?$_GET["zoom_query"]:"")  ."","OR","Includes",",%20","%20","%22","%22",0);
  $WADbSearch1->keywordComparison($KeyArr2,"".((isset($_GET["zoom_query"]))?$_GET["zoom_query"]:"")  ."","OR","Includes",",%20","%20","%22","%22",0);
  $WADbSearch1->keywordComparison($KeyArr3,"".((isset($_GET["zoom_query"]))?$_GET["zoom_query"]:"")  ."","OR","Includes",",%20","%20","%22","%22",0);
  $WADbSearch1->keywordComparison($KeyArr4,"".((isset($_GET["S_title"]))?$_GET["S_title"]:"")  ."","AND","Includes",",%20","%20","%22","%22",0);
  $WADbSearch1->keywordComparison($KeyArr5,"".((isset($_GET["S_sku"]))?$_GET["S_sku"]:"")  ."","AND","Includes",",%20","%20","%22","%22",0);
  $WADbSearch1->keywordComparison($KeyArr6,"".((isset($_GET["S_product"]))?$_GET["S_product"]:"")  ."","AND","Includes",",%20","%20","%22","%22",0);
  $WADbSearch1->keywordComparison($KeyArr7,"".((isset($_GET["S_fname"]))?$_GET["S_fname"]:"")  ."","AND","Includes",",%20","%20","%22","%22",0);
  $WADbSearch1->keywordComparison($KeyArr8,"".((isset($_GET["S_email"]))?$_GET["S_email"]:"")  ."","AND","Includes",",%20","%20","%22","%22",0);
  $WADbSearch1->addComparisonFromEdit("tbl_orders.dateinsert","S_dateinsert","AND","=",2);
  $WADbSearch1->addComparisonFromEdit("tbl_orders.status","S_status","AND","=",0);
  $WADbSearch1->addComparisonFromEdit("tbl_orders.client","S_client","AND","=",1);



The zoom_query call is a single multi table search text box

Hope that helps.

Sign in to reply to this post

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?

Sign in to reply to this post

Dave BuchholzBeta Tester

Steven,

interesting approach, to answer your question about natural language search no I don't believe it does.

Because you are using

php:
//comparison list additions

  $WADbSearch1->addComparisonFromList("id","search","OR","=",1);



I believe the code is expecting an integer, I am sure Jason will correct me if I am wrong.

Sign in to reply to this post

Peterson Design Studio - jefferis

Thanks Dave,
Did you add the code after you created the initial pages with the DB Create Pages function? Or did you just add a search function to a single page to start ?

I tried to use the Create pages function yesterday, and it started auto creating the search pages but then stalled and stopped and said i needed to create ether a recordset or a connection (can't remember) for the pages. That didn't make any sense because I started with a page with a connection (even though the create pages function doesn't use that page when it creates) .

Anyway, it just stalled out after creating one page.

Sign in to reply to this post

Dave BuchholzBeta Tester

Jefferis,

I have a set of "standard" pages that are the starting point for my projects which already have the base code on so I guess the answer to your question is after

Sign in to reply to this post

Peterson Design Studio - jefferis

I am trying to set up a multi table query but am getting an error

mysql_select_db($database_BEN, $BEN);
$query_AdminStuff = "SELECT * FROM users, requests WHERE requests.Dealer_ID = users.Dealer_ID";
setQueryBuilderSource($query_AdminStuff,$WADbSearch1,false); //// LINE 50
$AdminStuff = mysql_query($query_AdminStuff, $BEN) or die(mysql_error());
$row_AdminStuff = mysql_fetch_assoc($AdminStuff);
$totalRows_AdminStuff = mysql_num_rows($AdminStuff);

dump values are: array(0) { }

Fatal error: Call to undefined function setQueryBuilderSource() in /services/webpages/b/e/ben.com/public/benadmin/admin.php on line 50

Any Ideas what might be wrong?

Sign in to reply to this post

Jason ByrnesWebAssist

please send a copy of the page so i can see the code in context.

Sign in to reply to this post

Peterson Design Studio - jefferis

Thanks Jason

Attached Files
admin.php.zip
Sign in to reply to this post

Jason ByrnesWebAssist

the error is caused by code order.

lines 55- 95:

php:
<?php require_once("../webassist/database_management/wada_search.php"); ?>

<?php
//WA Database Search (Copyright 2005, WebAssist.com)
//Recordset: AdminStuff;
//Searchpage: adminsearch.php;
//Form: form1;
$WADbSearch1_DefaultWhere "";
if (!
session_id()) session_start();
if ((isset(
$_POST["WADbSearch1"])) && ($_POST["WADbSearch1"] != "")) {
  
$WADbSearch1 = new FilterDef;
  
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
  
//keyword array declarations
  
$KeyArr0 = array("UserEmail""UserFirstName""UserLastName""UserCity""UserState""UserZip""UserPhone""UserAddress""Dealer_ID""Orderkey""Jewelry_Type""Setting_Style");

  
//comparison list additions
  
$WADbSearch1->keywordComparison($KeyArr0,"".((isset($_POST["SearchDealers"]))?$_POST["SearchDealers"]:"")  ."","AND","Includes",",%20","%20","%22","%22",0);

  
//save the query in a session variable
  
if (== 1) {
    
$_SESSION["WADbSearch1_admin"]=$WADbSearch1->whereClause;
  }
}
else     {
  
$WADbSearch1 = new FilterDef;
  
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
  
//get the filter definition from a session variable
  
if (== 1)     {
    if (isset(
$_SESSION["WADbSearch1_admin"]) && $_SESSION["WADbSearch1_admin"] != "")     {
      
$WADbSearch1->whereClause $_SESSION["WADbSearch1_admin"];
    }
    else     {
      
$WADbSearch1->whereClause $WADbSearch1_DefaultWhere;
    }
  }
  else     {
    
$WADbSearch1->whereClause $WADbSearch1_DefaultWhere;
  }
}
$WADbSearch1->whereClause str_replace("\\''""''"$WADbSearch1->whereClause);
$WADbSearch1whereClause '';
?>




should be moved to line 12 so it comes before the recordset.

Sign in to reply to this post
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...