现在想在文章列表进行筛选,根据标签筛选出对应标签的文章
但是不能用like。SO,FIND_IN_SET函数就大显身手了
FIND_IN_SET(str,strlist)
str 要查询的字符串
strlist 字段名 参数以”,”分隔 如 (1,2,6,8,10,22)
查询字段(strlist)中包含(str)的结果,返回结果为null或记录
倘若想搜索标签ID为2的文章:
SELECT id,label FROM dk_info where FIND_IN_SET ('2',label)
倘若想搜索标签ID为3的文章:
SELECT id,label FROM dk_info where FIND_IN_SET ('3',label)
SELECT t.内容,p.标签 ,o.分类名 FROM `文章` t LEFT JOIN (select `文章Id`, GROUP_CONCAT(`标签名` separator ',') 标签 from 标签 group by `文章Id`) p on t.id= p.文章Id LEFT JOIN 分类 o on o.分类id=t.分类id参考资料:meizhi520.com/read/4824
$arr1 = mysql_query("select content from tbName where tag1 = $arg1 or tag2 = $arg1 or tag3 = $arg1")$arr2 = mysql_query("select content from tbName where tag1 = $arg2 or tag2 = $arg2 or tag3 = $arg2")
$arr3 = mysql_query("select content from tbName where tag1 = $arg3 or tag2 = $arg3 or tag3 = $arg3")
$result = array_merge( $arr1, $arr2, $arr3 )
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)