我的while循环在内部执行了另一个查询后停止...你能纠正我的代码吗?我想将表ordered_items_supplier中的列状态更新为"待定"当在purchase_items_supplier表中找到pi_number时,如果没有找到,则列状态为" Active"。
$sql2 = "select * from ordered_items_supplier";
$result = $connect->query($sql2);
if($result->num_rows > 0){
while ($row = $result->fetch_assoc()) {
$pi_number = $row['pi_number'];
$sql = "select * from purchased_items_supplier where pi_number = '$pi_number'";
$result = $connect->query($sql);
if($result->num_rows > 0){
while ($row2 = $result->fetch_assoc()) {
$pi_number = $row2['pi_number'];
$sql = "update ordered_items_supplier set status = 'Pending' where pi_number = '$pi_number'";
$query = $connect->query($sql);
}
}else{
$sql = "update ordered_items_supplier set status = 'Delivered' where pi_number = '$pi_number'";
$query = $connect->query($sql);
}
}
}
答案 0 :(得分:2)
问题是每次都覆盖相同的变量。
检查您是否使用$result
作为外部和内部查询。这就是问题发生的原因。所以不要覆盖$result
变量。