DreamWeaver CS3 database searching

I have built a search form for my database that is functioning.  I have a simple form to use in the search.  I need to be able to search for multiple terms passed from one text field from the search form.  
For example:  search for   apples oranges
the result should be anything in the column that has both 'apples' and 'oranges', or whatever terms are typed in with a space between them.

I have had problems trying to get the results to behave when using a Date field in the form as well.
<?php require_once('../Connections/WCI.php'); ?>
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  return $theValue;
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_SearchResults = 15;
$pageNum_SearchResults = 0;
if (isset($_GET['pageNum_SearchResults'])) {
  $pageNum_SearchResults = $_GET['pageNum_SearchResults'];
$startRow_SearchResults = $pageNum_SearchResults * $maxRows_SearchResults;
$varcontact_SearchResults = "%";
if (isset($_GET['Contact'])) {
  $varcontact_SearchResults = $_GET['Contact'];
$varlong_SearchResults = "%";
if (isset($_GET['Long_Desc'])) {
  $varlong_SearchResults = $_GET['Long_Desc'];
mysql_select_db($database_WCI, $WCI);
$query_SearchResults = sprintf("SELECT `Date`, Hours, Contact, Long_Desc FROM Results WHERE Contact LIKE %s AND Long_Desc LIKE %s ORDER BY `Date` DESC", GetSQLValueString("%" . $varcontact_SearchResults . "%", "text"),GetSQLValueString("%" . $varlong_SearchResults . "%", "text"));
$query_limit_SearchResults = sprintf("%s LIMIT %d, %d", $query_SearchResults, $startRow_SearchResults, $maxRows_SearchResults);
$SearchResults = mysql_query($query_limit_SearchResults, $WCI) or die(mysql_error());
$row_SearchResults = mysql_fetch_assoc($SearchResults);
if (isset($_GET['totalRows_SearchResults'])) {
  $totalRows_SearchResults = $_GET['totalRows_SearchResults'];
} else {
  $all_SearchResults = mysql_query($query_SearchResults);
  $totalRows_SearchResults = mysql_num_rows($all_SearchResults);
$totalPages_SearchResults = ceil($totalRows_SearchResults/$maxRows_SearchResults)-1;
$queryString_SearchResults = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_SearchResults") == false && 
        stristr($param, "totalRows_SearchResults") == false) {
      array_push($newParams, $param);
  if (count($newParams) != 0) {
    $queryString_SearchResults = "&" . htmlentities(implode("&", $newParams));
$queryString_SearchResults = sprintf("&totalRows_SearchResults=%d%s", $totalRows_SearchResults, $queryString_SearchResults);

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason C. LevineNo oneCommented:
>>  I need to be able to search for multiple terms passed from one text field from the search form.  

You can't easily do this with the built-in behaviors.  You either need to know how to write some PHP code that splits the input string into separate words and builds an OR clause for each one or you need to invest in an extension for DW that automates this.
prostangAuthor Commented:
I know how to write some PHP.  DreamWeaver makes it so much easier.
Jason C. LevineNo oneCommented:
So which solution would like guidance on?  
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

prostangAuthor Commented:
I don't really care about the date issue.  I really would like to break down the search field.
Jason C. LevineNo oneCommented:
Do you want me to recommend an extension or give you direction on the functions in PHP and you can attempt to code it yourself?
prostangAuthor Commented:
if you can recommend and extension that will work.  I am running out of time to tackle the coding at this point.  Sorry for the delay in my post.
Jason C. LevineNo oneCommented:
DataAssist from WebAssist has a wizard that will build a very advanced search routine.  Multiple form fields, multiple parameters are all possible:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
prostangAuthor Commented:
thanks.  How much work is it to do it manually?
Jason C. LevineNo oneCommented:
Depends on you, really.

The way to go is to use the explode() function on the input string to get each word as an element of an array:


You then step through the array and build the WHERE clause in the query with OR statements, one for each element in the array.  A similar example is here:

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Dreamweaver

From novice to tech pro — start learning today.