$query = "SELECT * FROM business_directory WHERE
Name LIKE '% $businesstype %' OR Name LIKE '$businesstype %' OR Name LIKE '% $businesstype'";
My question now is: Is it possible, and what would the correct syntax be to also match $businesstype(s), thereby finding designer(s) when a search is carried out for 'designer'? I should know this by now!
Last edited by zoe on Thu Dec 01, 2005 8:48 am, edited 1 time in total.
I"m not sure what you mean? You mean you want to match the designer to the business variable as well? Or the designers are listed in a different table, or you want to match designers to a different variable?
When $businesstype = 'designer', I want it also to match 'designers'. It's just that most people enter their details as, for example Anonymous Web Designers Ltd, and most site users will search for designer, rather than designers. I want to open up the search to include plurals, but not for example, a search for 'car' producing results that include 'carpet'.
Last edited by zoe on Fri Nov 25, 2005 12:13 pm, edited 1 time in total.
$designers = array("designer1","designer2");
if(in_array($businesstype, $designers))
$where = "designer like '%$businesstype%'";
else
$where = "Name LIKE '% $businesstype %' OR Name LIKE '$businesstype %' OR Name LIKE '% $businesstype'";
$query = "SELECT * FROM business_directory WHERE $where";
well using the like operator may not be your best solution. I'd suggest you look at using a full-text index search as that will accomplish what you're trying to do.
$query = "SELECT *, MATCH (Name, Type, Keywords) AGAINST ('$businesstype' IN BOOLEAN MODE) FROM business_directory WHERE MATCH (Name, Type, Keywords) AGAINST ('$businesstype')";
with the full text index you don't need to worry about it.
the full text indexed search should find things like "designer" when you're searching for "designers". It will however not find "car" when searching for "carpet".
I've taken a bit of a break from this one, but it doesn't seem to have gone away!
If the query I posted above should work correctly and return table entries containing 'designers' when the user asks for 'designer', I must be doing something else wrong.
$businesstype = ($_GET['businesstype']);
$query = "SELECT *, MATCH (Name, Type, Keywords) AGAINST ('$businesstype' IN BOOLEAN MODE) FROM business_directory WHERE MATCH (Name, Type, Keywords) AGAINST ('$businesstype' IN BOOLEAN MODE)";
$result = mysql_query($query);
echo (mysql_num_rows($result));
I've cut the code right back. When $businesstype = 'designers', I get 12 results, but for 'designer' I get 0.
Anyone any ideas what I'm mising? The page in question is at http://www.g63directory.com/searchResults1.php if it's any help. Many thanks.