tags:

views:

57

answers:

3

hi to all..

i am using php and mysql...

i have application in which user enter any text and i want to fiind related data from database without using "LIKE" cause in my mysql query.

is there any possible way to search these string in database.

or any approach in mysql to do this....

Thanks in advance.

+1  A: 

You can use REGEXP, when user put single word you put WHERE field REGEXP '.*TEXT.*' in your query, regex is cool because you can allow user to put regular expression in search field.

jcubic
@Sanjay: Time to learn regular expression ;) http://en.wikipedia.org/wiki/Regular_expression
r3zn1k
@jcubic - we can also do it with match().
Sanjay
+2  A: 

You can also check out MATCH clause.

Tomasz Kowalczyk
+1 for fulltext search, if he's using mysql anyway. He may need to switch to myisam, but I'm guessing he's already using that.
Maerlyn
A: 

If you don't want to use LIKE, and don't give a reason why (it seems fine for everyone else) then here is a solution that gets you araound it. (But it might not be the best real-world option...)

Whenever anything is added to the database that you want to be searched, take each word and break it into every possible combination of 1 or more consecutive letters.

E.g. for stack:

s, t, a, c, k, st, ta, ac, ck, sta, tac, ack, stac, tack, stack

Insert each of these into a table with an identifier that links to the original data.

Then you can match any search query against this list of words eactly (for full and partial matches). If your user is searching for multiple keywords, you split them in the front and and search for each, looking for matches to the same identifier.

ck