close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

combining search fields into one

Thread began 7/09/2011 7:11 am by info97301 | Last modified 7/13/2011 10:49 am by Jason Byrnes | 3517 views | 21 replies |

info97301

combining search fields into one

Hi

I've used DA to create search/results pages. Currently there are 3 search boxes, for the fields PgTitle, PgDesc and PgDetails.

This search works fine (additional parameters are used to restrict records to SiteID etc).

What I would like to do is have one search field, which looks for matches in any of those 3 fields.

I've tried changing the following in different ways:

//comparison list additions
$WADbSearch1->addComparisonFromEdit("PgTitle","S_PgTitle","AND","Includes",0);
$WADbSearch1->addComparisonFromEdit("PgDesc","S_PgDesc","AND","Includes",0);
$WADbSearch1->addComparisonFromEdit("PgDetails","S_PgDetails","AND","Includes",0);

However, when I try to combine them into one, I either get ALL records for the particular SiteID or no records (even though I am testing with criteria I know should work).

ANy suggestions? I might well be looking at the wrong piece of code - but I can't see anything else that looks likely.

Many thanks
Chris

Sign in to reply to this post

CraigRBeta Tester

Are you trying to do the search from a single text field ?

lets call your single search text field 'searchtext'

try this

//comparison list additions
$WADbSearch1->addComparisonFromEdit("PgTitle","searchtext","AND" ,"Includes",0);
$WADbSearch1->addComparisonFromEdit("PgDesc","searchtext","AND"," Includes",0);
$WADbSearch1->addComparisonFromEdit("PgDetails","searchtext"," AND","Includes",0);

Sign in to reply to this post

info97301

HI Craig

Thanks - that's what I thought it would be, but I've tried it already and it didn't work.

Also tried changing "AND" to "OR", equally without success.

Cheers
Chris

Sign in to reply to this post

info97301

Just noticed the differeny spacing around "AND" - either "AND ", "AND" or " AND". Don't know if this will make a difference, but will experiment tomorrow (late now!) and feedback.

Chris

Sign in to reply to this post

Dave BuchholzBeta Tester

This is a sample of code that I use to perform single field text searches. I use GET rather than POST in this instance but it should give you the basis to get started

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

//Recordset: rsDataSet;
//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("PgTitle");
  $KeyArr1 = array("PgDesc");
  $KeyArr2 = array("PgDetails");

  //comparison list additions
  $WADbSearch1->keywordComparison($KeyArr0,"".((isset($_GET["searchtext"]))?$_GET["searchtext"]:"")  ."","AND","Includes",",%20","%20","%22","%22",0);
  $WADbSearch1->keywordComparison($KeyArr1,"".((isset($_GET["searchtext"]))?$_GET["searchtext"]:"")  ."","OR","Includes",",%20","%20","%22","%22",0);
  $WADbSearch1->keywordComparison($KeyArr2,"".((isset($_GET["searchtext"]))?$_GET["searchtext"]:"")  ."","OR","Includes",",%20","%20","%22","%22",0);
Sign in to reply to this post

info97301

Hi Dave

Many thanks for replying.

I'm using 'GET' so that the SiteID and lang parameters are captured.

Unfortunately, I'm not making any progress. All pages belonging to the SiteID are returned - at least it's not returning others'!

The form code:
<form action="search_results2.php" method="get" name="WADASearchForm" id="WADASearchForm">
<div class="WADAHorizLine"></div>
<table class="WADADataTable" cellpadding="0" cellspacing="0" border="0">
<tr>
<th class="WADADataTableHeader"><span class="WADADataNavButtonCell">
<input name="SiteID" type="hidden" id="SiteID" value="<?php echo $_GET['SiteID']; ?>" />
<input name="lang" type="hidden" id="lang" value="<?php echo $_GET['lang']; ?>" />
</span>Page Title:</th>
<td class="WADADataTableCell"><input type="text" name="searchtext" id="searchtext" value="" size="32" /></td>
</tr>
</table>
<div class="WADAHorizLine"></div>
<div class="WADAButtonRow">
<table class="WADADataNavButtons" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="WADADataNavButtonCell" nowrap="nowrap"><input type="image" name="Search" id="Search" value="Search" alt="Search" src="WA_DataAssist/images/Pacifica/Refined_search.gif" /></td>
</tr>
</table>
</div>
</form>
----------------------
And I have copied your code to use the one field;
<?php
//WA Database Search (Copyright 2005, WebAssist.com)
//Recordset: WADApages;
//Searchpage: pages_Search.php;
//Form: WADASearchForm;
$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("PgTitle");
$KeyArr1 = array("PgDesc");
$KeyArr2 = array("PgDetails");

//comparison list additions
$WADbSearch1->keywordComparison($KeyArr0,"".((isset($_GET["searchtext"]))?$_GET["searchtext"]:"") ."","AND","Includes",",%20","%20","%22","%22",0);
$WADbSearch1->keywordComparison($KeyArr1,"".((isset($_GET["searchtext"]))?$_GET["searchtext"]:"") ."","OR","Includes",",%20","%20","%22","%22",0);
$WADbSearch1->keywordComparison($KeyArr2,"".((isset($_GET["searchtext"]))?$_GET["searchtext"]:"") ."","OR","Includes",",%20","%20","%22","%22",0);

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

Thanks again,

Chris

Sign in to reply to this post

Dave BuchholzBeta Tester

It depends on how you are filtering your recordset with the other two form variables

Sign in to reply to this post

info97301

Hi David

Thanks - it gave me a glimmer of hope. Until I tried changing $_GET['SiteID'] to $_POST['SiteID'] in the recordset. Unfortunately, it hasn't made any difference (I have changed the form from GET to POST too).

The three separate fields work fine with the original query, so I can't understand (not being a tecchie!) why the modification doesn't work.

Cheers
Chris

Sign in to reply to this post

Jason ByrnesWebAssist

send a copy of the search and results page so we can see the entire code in context please.

Sign in to reply to this post

info97301

Hi Jason

Third attempt at posting this!

I've just attached the results page, as this has the form on it too.

Many thanks

Chris
------------------

Attached Files
search_results2.txt
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...