Searching a text field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

Searching a text field

Post by chris12295 »

i need an effective way to search a text field in a database for a keyword, ive tried LIKE but it doesnt match unless someone types the exact contents and if u put LIKE %$var% it matches down to letters which isnt very relevant. i need to match words, can anyone help?
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

This should work :

Code: Select all

SELECT mycolumn FROM mytable WHERE mycolumn RLIKE "&#1111;&#1111;:<:]]$var&#1111;&#1111;:>:]]"
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

You can also avoid the Regular Expressions and just use this:

Code: Select all

SELECT field FROM table WHERE field LIKE '% word %'
Notice the spaces around 'word'.
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

that will work provided the word is not preceeded or followed by any punctuation or end of string markers.
Post Reply