close ad
WARNING PC USERS: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

One keyword search for multiple tables?

Thread began 10/19/2009 1:34 pm by gary313807 | Last modified 7/30/2012 11:47 am by gary313807 | 3159 views | 17 replies

Dave BuchholzBeta Tester

I have implemented a one field one keyword search on T Shirt Town that searches the product, category and subcategory titles.

The search code looks like this:

php:
//WA Database Search (Copyright 2005, WebAssist.com)

//Recordset: rsProducts;
//Searchpage: search-form.php;
//Form: frmSearch;
$WADbSearch1_DefaultWhere = "";
if (!session_id()) session_start();
if ((isset($_GET["WADbSearch1"])) && ($_GET["WADbSearch1"] != "")) {
  $WADbSearch1 = new FilterDef;
  $WADbSearch1->initializeQueryBuilder("MYSQL","1");
  //keyword array declarations
  $KeyArr0 = array("tbl_products.title");
  $KeyArr2 = array("tbl_categories.title");
  $KeyArr3 = array("tbl_subcategories.title");

  //comparison list additions
  $WADbSearch1->keywordComparison($KeyArr0,"".((isset($_GET["zoom_query"]))?$_GET["zoom_query"]:"")  ."","AND","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->addComparisonFromEdit("tbl_gender.id","S_gender","AND","=",1);
  $WADbSearch1->addComparisonFromEdit("tbl_categories.id","S_category","AND","=",1);
  $WADbSearch1->addComparisonFromEdit("tbl_subcategories.id","S_subcategory","AND","=",1);
  $WADbSearch1->addComparisonFromEdit("tbl_products.id","S_design","AND","=",1);

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



and my recordset code looks like this:

php:
mysql_select_db($database_connDB, $connDB);

$query_rsProducts = "SELECT tbl_categories.title AS category, tbl_categories.url AS categoryURL, tbl_subcategories.title AS subcategory, tbl_subcategories.url AS subcategoryURL, tbl_products.title AS product, tbl_products.url AS productURL, tbl_products.details AS productDetails, tbl_products.id AS productID, tbl_products.image AS productImage, tbl_products.image2 AS productImage2, tbl_products.image3 AS productImage3, tbl_categories.id AS categoryID, tbl_subcategories.id AS subcategoryID, tbl_prodtypes.url AS prodtypeURL, tbl_prodtypes.id AS prodtypeID, tbl_gender.title AS gender, tbl_gender.url AS genderURL FROM tbl_products JOIN tbl_lnkprodcatsubcat ON (tbl_products.id = tbl_lnkprodcatsubcat.productsID) JOIN tbl_categories ON (tbl_lnkprodcatsubcat.categoriesID = tbl_categories.id) JOIN tbl_subcategories ON (tbl_lnkprodcatsubcat.subcategoriesID = tbl_subcategories.id) JOIN tbl_lnkproductprodtypes ON (tbl_lnkprodcatsubcat.productsID = tbl_lnkproductprodtypes.productsID) JOIN tbl_prodtypes ON (tbl_lnkproductprodtypes.prodtypesID = tbl_prodtypes.id) JOIN tbl_gender ON (tbl_prodtypes.fk = tbl_gender.id) WHERE tbl_categories.publish = 1 AND tbl_subcategories.publish = 1 AND tbl_products.publish = 1 AND tbl_prodtypes.publish = 1 GROUP BY tbl_products.id ORDER BY tbl_categories.sortorder ASC, tbl_subcategories.sortorder ASC, tbl_products.sortorder ASC, tbl_products.title DESC";
setQueryBuilderSource($query_rsProducts,$WADbSearch1,false);
$query_limit_rsProducts = sprintf("%s LIMIT %d, %d", $query_rsProducts, $startRow_rsProducts, $maxRows_rsProducts);
$rsProducts = mysql_query($query_limit_rsProducts, $connDB) or die(mysql_error());
$row_rsProducts = mysql_fetch_assoc($rsProducts);



Hope that helps someone

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