I am programming in php and MySQL and have a question about searching my database.

My search page works OK, but I want my search engine to find results even if the return records don't contain the exact text string the user entered in the form, for example, records with the keywords in a different order or separated by other words.

Can anyone help me accomplish this?

Thanks,
Lavern


Here is the code:

[php]<?php
$maxRows_SearchInventory = 10;
$pageNum_SearchInventory = 0;
if (isset($HTTP_GET_VARS['pageNum_SearchInventory'])) {
$pageNum_SearchInventory = $HTTP_GET_VARS['pageNum_SearchInventory'];
}
$startRow_SearchInventory = $pageNum_SearchInventory * $maxRows_SearchInventory;


mysql_select_db($database_Lighthouse, $Lighthouse);

// The basic SELECT statement
$select = 'SELECT DISTINCT *';
$from = ' FROM onlinestore';
$where = ' WHERE 1=1';

$division = $_GET['division'];
if ($division !='') { // A division is selected
$where .= " AND Category LIKE '$division'";
}

$cid = $_GET['cid'];
if ($cid != '') { // A category is selected
$from .= ', ItemLookup';
$where .= " AND name=PID AND CID='$cid'";
}

$searchtext = $_GET['searchtext'];
$searchfield = $_GET['searchfield'];
if ($searchtext != '') { // Some search text was specified
$where .= " AND $searchfield LIKE '%$searchtext%'";
}

$viewdivision = $_GET['viewdivision'];
if ($viewdivision !='') { // A division is selected
$where .= " AND Category LIKE '$viewdivision'";
}

$viewcid = $_GET['viewcid'];
if ($viewcid != '') { // A category is selected
$from .= ', ItemLookup';
$where .= " AND name=PID AND CID='$viewcid'";
}

$sidedivision = $_GET['sidedivision'];
if ($sidedivision !='') { // A division is selected
$where .= " AND Category LIKE '$sidedivision'";
}

$sidecategory = $_GET['sidecategory'];
if ($sidecategory != '') { // A category is selected
$from .= ', ItemLookup';
$where .= " AND name=PID AND CID='$sidecategory'";
}

$sidesearchtext = $_GET['sidesearchtext'];
$sidefield = $_GET['sidefield'];
if ($sidesearchtext != '') { // Some search text was specified
$where .= " AND $sidefield LIKE '%$sidesearchtext%'";
}

$order = ' ORDER BY Title ASC';
$query_SearchInventory = ($select . $from . $where.$order);
$query_limit_SearchInventory = sprintf("%s LIMIT %d, %d", $query_SearchInventory, $startRow_SearchInventory, $maxRows_SearchInventory);
$SearchInventory = mysql_query($query_limit_SearchInventory, $Lighthouse) or die(mysql_error());
$row_SearchInventory = mysql_fetch_assoc($SearchInventory);
$totalRows_SearchInventory = mysql_num_rows($SearchInventory);

if (isset($HTTP_GET_VARS['totalRows_SearchInventory'])) {
$totalRows_SearchInventory = $HTTP_GET_VARS['totalRows_SearchInventory'];
} else {
$all_SearchInventory = mysql_query($query_SearchInventory);
$totalRows_SearchInventory = mysql_num_rows($all_SearchInventory);
}
$totalPages_SearchInventory = ceil($totalRows_SearchInventory/$maxRows_SearchInventory)-1;

$queryString_SearchInventory = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_SearchInventory") == false &&
stristr($param, "totalRows_SearchInventory") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_SearchInventory = "&" . implode("&", $newParams);
}
}
$queryString_SearchInventory = sprintf("&totalRows_SearchInventory=%d%s", $totalRows_SearchInventory, $queryString_SearchInventory);

?>[php]