我能够绑定 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);
1 回答
心有法竹
TA贡献1866条经验 获得超5个赞
您将不得不将两个列表组合在一起,然后将它们一次性绑定......
$params = array_merge($_POST['category'],$_POST['location']);
$stmt->bind_param(str_repeat('s', count($params)), ...$params);
- 1 回答
- 0 关注
- 94 浏览
添加回答
举报
0/150
提交
取消