我能够绑定 1 个数组作为参数没问题。但是,我正在尝试将 2+ 个数组绑定为参数,但效果不是很好。解包后我不断收到无法使用位置参数的错误。如何将数组组合为参数?
$query="SELECT price FROM products WHERE status='1'";
if(isset($_POST['category'])){
$category_filter = join(',', array_fill(0, count($_POST['category']), '?'));
$sql .= ' AND category IN ('.$category_filter.')';
}if(isset($_POST['location'])){
$location_filter = join(',', array_fill(0, count($_POST['location']), '?'));
$sql .= ' AND location IN ('.$location_filter.')';
}
$stmt = $conn->prepare($query);
$stmt->bind_param(str_repeat('ss', count($_POST['category'],$_POST['location'])), ...$_POST['category'],...$_POST['location']);
$stmt->execute();
$stmt->bind_result($price);
心有法竹