Reputation: 23662
SELECT * FROM disney;
+++++++NAME+++++++
lion king
cinderella
the little mermaid
+++++++++++++++++++
$string = "i love the movie lion king, it rocks!"
I want to get the NAME from disney where the NAME is inside the given string. It's kinda like:
'SELECT * FROM disney WHERE NAME LIKE "%'.$string.'%";'
only the other way around (but didn't work well when i tried it).
Is there a MYSQL function to check whether a data in a table cell exists in a given string?
Thanks a lot! ().i'm working with PHP!
Upvotes: 0
Views: 106
Reputation: 11576
There's the INSTR Function which should work for this:
SELECT * FROM disney WHERE INSTR('i love the movie lion king, it rocks!', name) > 0
Upvotes: 1
Reputation: 10174
You can also try MySQL's FULLTEXT search feature which only works with MyISAM tables:
$query = "SELECT * FROM disney WHERE MATCH(NAME) AGAINST ('$text')";
Upvotes: 0
Reputation: 21773
I think the following should work (I remember trying to do the same once, and I think this is what I used) :
'SELECT * FROM disney WHERE "' . $string . '" LIKE CONCAT("%",NAME,"%")';
Upvotes: 1