表arts
列tags
-示例:
sky, code, earth, codepen
$tag = 'code';
$sql = "select * from arts where tags like ('%" . $tag . "%')";
结果-code, codepen
结果只需要code
,即这样的东西:
$sql = "select * from arts where tags contains only (' . $tag . ')";
有帮助吗?
答案 0 :(得分:2)
您可以使用FIND_IN_SET来检查CSV列中的值。
$sql = "select * from arts where FIND_IN_SET('" . $tag . "', tags)";