thinkphp5.1 where使用FIND_IN_SET:
数据库的值
id type
1 1,4,5
2 1,2,4
3 2,3
4 2,4
5 4,5
6 2,5
查出所有type含4的数据,就要用FIND_IN_SET $where = 'FIND_IN_SET('.$type.' ,REPLACE(type, "-", ","))'; $list = ModelTestType::where($where)->select();
数据库的值
id type
1 1,4,5
2 1,2,4
3 2,3
4 2,4
5 4,5
6 2,5
查出所有type含4的数据,就要用FIND_IN_SET $where = 'FIND_IN_SET('.$type.' ,REPLACE(type, "-", ","))'; $list = ModelTestType::where($where)->select();