每当我尝试使用for循环更新多于一行的记录时,它只会更新记录的第一行,但是当我仅更新一行时。很好。
我将赞赏一种解决方案或更好的方法。 谢谢。
$select_ids = $conn->query("SELECT id FROM `pet_medicals_treat` WHERE med_id = '$id'");
$count = $select_ids->num_rows;
$row_id = $select_ids->fetch_array(MYSQLI_NUM);
for ($i = 0; $i < $count; $i++) {
if (trim($_POST['pet_treat'][$i]) != '') {
$rows = $row_id[$i];
$pet_treat = $_POST['pet_treat'][$i];
$pres_one = $_POST['pres_one'][$i];
$pres_two = $_POST['pres_two'][$i];
$pres_three = $_POST['pres_three'][$i];
$pres_qty = $_POST['med_qty'][$i];
$query = $conn->query("UPDATE pet_medicals_treat SET pet_treat='$pet_treat',pres_one='$pres_one',
pres_two='$pres_two',pres_three='$pres_three',pres_qty='$pres_qty' WHERE id ='$rows'");
}
}