我在cookie中有一个id数组。
当我打印cookie数组时,它打印如下:
["39","580"]
。我需要访问id
39
和580
。
我在这样的查询中尝试了所有我需要的东西:
$queryordenar = $db->prepare("SELECT id FROM property
WHERE id IN (:list) ORDER BY price ASC");
$queryordenar->execute(array(
'list' => $array
));
由于
答案 0 :(得分:3)
您无法将数组作为参数传递。你需要爆炸数组,传入一个?对于每个值,然后将正确的值绑定到每个占位符:
$bindPlaceholders = [];
foreach ($array as $val) {
$bindPlaceholders[] = "?";
}
$bindString = "(".implode(",", $bindPlaceholders).")";
$queryordenar = $db->prepare("SELECT id FROM property WHERE id IN ".$bindString." ORDER BY price ASC");
foreach ($array as $i => $val) {
$queryordenar->bindValue($i + 1, $val); // binding starts at 1
}
$queryordenar->execute();