thinkphp6 find_in_set使用实例

FIND_IN_SET(str,strlist)

str 要查询的字符串
strlist 字段名 参数以”,”分隔 如 (1,2,6,8)
查询字段(strlist)中包含(str)的结果,返回结果为null或记录

$main_category =[3,4];

if
(!empty($main_category)) { $sql_category=''; foreach($main_category as $v){ $sql_category .= "FIND_IN_SET('{$v}',main_category) and "; } $sql_category = rtrim($sql_category," and "); $map[] = ['', 'exp', Db::raw($sql_category)]; }
var_dump($map);
搜索3,4的主营类目。如果用in方法就会搜索遗漏数据

 

 

 

 

 

posted on 2021-02-03 10:06  kevin_yang123  阅读(4615)  评论(0编辑  收藏  举报