我有一个包含六个元素($categories = array('dinner','casual','wedding')
)的数组,我想创建一个如下所示的SQL查询:
SELECT *
FROM produts
WHERE id = /* values of array $categories... eg. (dinner || casual || wedding) */
答案 0 :(得分:1)
试试这个:
$conditions = '';
foreach($categories as $cat) {
$conditions[] = " id = '".$cat."'";
}
$sql = 'SELECT * FROM produts WHERE '.implode(" OR ", $conditions);
答案 1 :(得分:-1)
您必须使用IN而不是WHERE。