我想检索类似的项目:
$formatsArray = $_POST['formats'];
$topicsArray = $_POST['topics'];
// Converting the array into individual strings
$formats = implode("','", $formatsArray);
$topics = implode("','", $topicsArray);
$resources = "select * from resources where
format IN ('".$formats."')
AND topic IN ('".$topics."')";
我的问题是,我不确定如何在查询中集成“%”。因为假设主题是
Idea Generation
,而mysql表是Idea Generation,Customer Development
,所以它将不匹配。 最佳答案
虽然有更好的方法可以做到这一点,但这应该是可行的:
$formats = implode("% OR format LIKE %", $formatsArray);
$topics = implode("% OR topic LIKE %", $topicsArray);
$query = "SELECT * from resources WHERE (format LIKE %" . $formats . "%) AND (topic LIKE %" . $topics ."%)"
这看起来有点像黑客,但应该适合你的情况。