我试图根据WHERE条件从我的数据库中获取一些数组,并且需要根据该数组从另一个表执行搜索。我试图这样做,但是我犯了几个错误。
代码是:
$sql = "SELECT post_id FROM flat_booking where buyer_mobile='$mobile'";
$result = mysqli_query($con,$sql);
$post_id = array();
while(($row = mysqli_fetch_assoc($result))) {
$post_id[] = $row['id'];
}
$sql = "SELECT id,area,furnished,image,numberofrooms,price,type FROM flatowner where id IN '$post_id'";
也许这一行引发了错误:
$post_id[] = $row['id'];
答案 0 :(得分:0)
您可以尝试使用JOINS来减少必须执行的查询量,并绕过必须在后续查询中传入逗号分隔列表。尝试类似下面的查询。
SELECT
O.id,
O.area,
O.furnished,
O.image,
O.numberofrooms,
O.price,
O.type
FROM flatowner O
INNER JOIN flat_booking B ON O.id = B.post_id
WHERE B.buyer_mobile = '$mobile'