我尝试在我的表更新多条记录,以便我只是得到了更新的最后一条记录我想知道是否there's什么不对这个脚本..这是完整的代码http://pastie.org/5453954更新MySQL中的多条记录
for ($i = 0; $i < count($_POST['id_servtype']); $i++){
$servtype = $_POST['id_servtype'][$i];
$project = $_POST['id_project'][$i];
$quantity = $_POST['tableQuantity'][$i];
$pus = $_POST['tablePus'][$i];
$puc = $_POST['tablePuc'][$i];
$totalitem = $_POST['tableTotal'][$i];
$sql = "update sales_order_items
set
id_project=?,
id_service_type=?,
quantity=?,
unit_price_no_tax=?,
unit_price=?,
total_item_imp=?
where
id_so=?
and
id_soitems=?
";
$stmt = $this->dbh->prepare($sql);
$stmt->bindValue(1, $project, PDO::PARAM_INT);
$stmt->bindValue(2, $servtype, PDO::PARAM_INT);
$stmt->bindValue(3, $quantity, PDO::PARAM_STR);
$stmt->bindValue(4, $pus, PDO::PARAM_STR);
$stmt->bindValue(5, $puc, PDO::PARAM_STR);
$stmt->bindValue(6, $totalitem, PDO::PARAM_STR);
$stmt->bindValue(7, $_POST["id"], PDO::PARAM_STR);
$stmt->bindValue(8, $_POST["iditem"], PDO::PARAM_STR);
$stmt->execute();
}
echo("Correct edition");
尝试打印$ _POST ['id_servtype'],看看你正在迭代,也许它不是你认为它应该是 –
我刚刚打印出来,即时获得相同的价值每行无论我改变..这是发生在$ servtype = $ _POST ['id_servtype'];和 $ project = $ _POST ['id_project']; – adavia