情况如下:
数据库记录举例如下:字段1 字段2
id class
1 01,02,03,04
2 03,05,09,10
3 05,11,15,17
4 03,04,07,09
5 01,03,04,15例如:
变量
$siteclass="02,03,05";需求效果目的:
检索出class字段内容所有包含有02或03或05的记录,包含有其中一个就可以
难道要把$siteclass的内容拆开来检索3次:
...where class like '%"02"%'
...where class like '%"03"%'
...where class like '%"05"%'
这样吗?这种情况下能不能只用一句就匹配完的方法呢?
数据库记录举例如下:字段1 字段2
id class
1 01,02,03,04
2 03,05,09,10
3 05,11,15,17
4 03,04,07,09
5 01,03,04,15例如:
变量
$siteclass="02,03,05";需求效果目的:
检索出class字段内容所有包含有02或03或05的记录,包含有其中一个就可以
难道要把$siteclass的内容拆开来检索3次:
...where class like '%"02"%'
...where class like '%"03"%'
...where class like '%"05"%'
这样吗?这种情况下能不能只用一句就匹配完的方法呢?
拆开的我会写
可是02,03,05在$siteclass变量里呀
而且$siteclass的值是不定的,每次都不同
$class_arr=explode(",",$siteclass)
然后再拼成那个sql语句...
CONCAT(",",class, ",") REGEXP "(02|03|05)"