views:

24

answers:

2

I have a classifieds website, where users can search for items. The search should be in all fields with the name 'description' and 'headline'.

I am currently using 'like' syntax (SELECT * FROM db WHERE description LIKE '%string%' OR headline LIKE '%string%')

Problem is, if I have records with headlines like BMW it is enough to just type 'w' in the search field and they would be fetched.

I need to match entire words in the search string only.

If you need more input, I will update the Q...

+1  A: 

Use MySQL's full text searching or some third party full text search engine, like Sphinx. Both of this solutions will give you more power and control over the results you get from the database.

Jan Hančič
A: 

Consider using MySQL's REGEX (aka RLIKE) operator.

http://dev.mysql.com/doc/refman/5.1/en/regexp.html

Shaunak Kashyap