$result=mysql_query("SELECT* FROM name WHERE name like 'name1' OR name like 'name2'..."); HTML: I have more than 20 words add into SELECT FROM WHERE like. Is there anyway to short the code? Such as: $result=mysql_query("SELECT* FROM table WHERE name like (name1, name2, name3, name4...) ); Of course this code is wrong, just an analogy.
I don't think there are any such functions within MySQL, you must use the OR operator. http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html
HI koko5, I also tried RLIKE, but RLIKE like '%name1%'. And I want precise search 'name1' Do you have any good idea? Thanks.
You've to use RLIKE with regular expression : ...RLIKE '(john|doe)'; Code (markup): ^^Will match John Smith,Johnny B., Jack Doe and so on. For exact match use IN: SELECT * FROM table WHERE name IN ('John','Johnny'); Code (markup): RLIKE is synonym for REGEXP, so you must specify pattern instead of using % Hope it's clear now. Regards