用户通过复选框从HTML表单中选择一些参数:
例子:他们从100种可能的食材中选择鸡蛋、胡萝卜和豆类。
这些选择的参数存储在数组中,如$ingredients['eggs','carrots','beans'];
mysql查询必须输入鸡蛋=1,胡萝卜=1和豆类=1的名称结果
$db->query("SELECT name, FROM ingredients WHERE eggs=1, carrots=1, beans=1")->fetchall();
但是如果我有$ingredients有不同的大小呢?
谢谢你的帮助。
$where = "WHERE 1 ";
foreach($ingredients as $key=>$value){
$where.=" AND {$value}=1";
}