帝国cms做相关链接的时候,会碰到这样的问题,判断两个以","号分割分割的字符串是否含有交集,那么就可以使用MySQL正则匹配的方式进行判断。
看代码:
<?php $navinfor[keyboard]='批量,提取,李时珍,黄芪,帝国,图片,标题'; $jhc_key=','.str_replace(',',',|,',$navinfor['keyboard']).','; $t=$dbtbpre."ecms_news"; $jieguo=""; $h = $empire->query("select * FROM $t where concat(',',keyboard,',') regexp '$jhc_key' limit 10"); while($r = mysql_fetch_assoc($h)){ echo $r['title'],$r['keyboard'],PHP_EOL; } ?>
如果是帝国内容页的话,用灵动标签可以这样调用:
<?php $jhc_key=','.str_replace(',',',|,',$navinfor['keyboard']).','; $jhc_key1=str_replace(',','|',$navinfor['keyboard']); ?> [e:loop={"select * from phome_ecms_news where id<>'$navinfor[id]' and ( title regexp '$jhc_key1' or concat(',',keyboard,',') regexp '$jhc_key') order by id desc limit 10",0,24}]