Page 1 of 1

refining search query

Posted: Thu Aug 04, 2005 12:45 pm
by zoe
This is probably a very simple problem, but i can't think what to search for to get an answer without just asking...here goes

I'm selecting entries from my database based on the user's entry in to a form field named 'businesstype'. My query goes somehing like this:

Code: Select all

$query = ("SELECT * FROM business_directory WHERE Type LIKE '%$businesstype%'");
My question is, how can I structure the query to select any business that contains the user's search term only as a distinct word in the 'Type' field?

For example, if the user enters 'car', the results should include 'car dealers', but not 'caravan sites'.

Posted: Thu Aug 04, 2005 12:50 pm
by feyd
untested

Code: Select all

SELECT * FROM business_directory WHERE Type REGEXP('\b{$businesstype}\b')

Posted: Thu Aug 04, 2005 12:50 pm
by zoe
thanx, i'll try that now. :D

Posted: Thu Aug 04, 2005 12:58 pm
by zoe
That's returning no results for anything. I'm a bit out of my depth here. Should probably start reading up on REGEX :?
Thanks