I created a search field on a site that searches SQL records. It searches the title of an items and returns the results. It works fine except for one problem. The search is too strict. If I put in shirt it will return all items with the word "shirt" in the title. But if I put in "shirts" with the S on the end since none of the products have the exact word "shirts" in the title it returns no results. That is the first problem.
The second problem is I would like to be able to search more then one column like the title. I would like to search through some of the other columns like description and so on.
It was very hard for me to figure out how to do this for what I have so far, I am just not able to figure it out any further on my own. Can any one help me with this? This is the last part of the site that needs to be done before I can publish it live.
Here is the search I have so far:
<?php
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_products = 5;
$pageNum_products = 0;
if (isset($_GET['pageNum_products'])) {
$pageNum_products = $_GET['pageNum_products'];
}
$startRow_products = $pageNum_products * $maxRows_products;
$colname_products = "1";
if (isset($_GET['searchproducts'])) {
$colname_products = (get_magic_quotes_gpc()) ? $_GET['searchproducts'] : addslashes($_GET['searchproducts']);
}
mysql_select_db($database_mrlogo, $mrlogo);
$query_products = sprintf("SELECT * FROM products WHERE name LIKE '%%%s%%' ORDER BY name ASC", $colname_products);
$query_limit_products = sprintf("%s LIMIT %d, %d", $query_products, $startRow_products, $maxRows_products);
$products = mysql_query($query_limit_products, $mrlogo) or die(mysql_error());
$row_products = mysql_fetch_assoc($products);
if (isset($_GET['totalRows_products'])) {
$totalRows_products = $_GET['totalRows_products'];
} else {
$all_products = mysql_query($query_products);
$totalRows_products = mysql_num_rows($all_products);
}
$totalPages_products = ceil($totalRows_products/$maxRows_products)-1;
mysql_select_db($database_mrlogo, $mrlogo);
$query_catagory = "SELECT * FROM catagory_group";
$catagory = mysql_query($query_catagory, $mrlogo) or die(mysql_error());
$row_catagory = mysql_fetch_assoc($catagory);
$totalRows_catagory = mysql_num_rows($catagory);
$queryString_products = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_products") == false &&
stristr($param, "totalRows_products") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_products = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_products = sprintf("&totalRows_products=%d%s", $totalRows_products, $queryString_products);
?>
I did use some of the automated features in DW MX 2004 to get most of my php for the search just F.Y.I.
Thanks for any help anyone can provide.