I have a string in the form $string = 'London,Paris,Birmingham'
and I want to search multiple columns for occurences of these values.
我有一个$string = 'London,Paris,Birmingham'的字符串,我想搜索多个列来查找这些值的出现。
For example WHERE events.name, events.cities, events.counties IN (".($string).")
例如events.name, events。城市,事件。县(“(字符串)美元。”)
Can someone recommend me a simple and short way of doing something like this.
有人能给我推荐一种简单而简短的方法吗?
1 个解决方案
#1
5
Use the FIND_IN_SET function:
使用FIND_IN_SET函数:
WHERE ( FIND_IN_SET(events.name, mysql_real_escape_string($string)) > 0
OR FIND_IN_SET(events.cities, mysql_real_escape_string($string)) > 0
OR FIND_IN_SET(events.counties, mysql_real_escape_string($string)) > 0)
#1
5
Use the FIND_IN_SET function:
使用FIND_IN_SET函数:
WHERE ( FIND_IN_SET(events.name, mysql_real_escape_string($string)) > 0
OR FIND_IN_SET(events.cities, mysql_real_escape_string($string)) > 0
OR FIND_IN_SET(events.counties, mysql_real_escape_string($string)) > 0)