我有Order # || Product ID || Product Name || Quantity || DELIVER Buttons
1 || 1 || Sample Item 1 || 10 || DELIVER
1 || 2 || Sample Item 2 || 20 || DELIVER
1 || 3 || Sample Item 3 || 30 || DELIVER
,其中显示了我的客户想要购买的所有产品。我想用一个DELIVER ALL按钮从我的库存中扣除所有产品。最好的方法是什么?
gvOrderDetails(样本表)
GridView
以下是void DeductFromInventory()
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "UPDATE Products SET Quantity = Quantity - " + gvOrderDetails.SelectedRow.Cells[3].Text + " WHERE ProductID=@ProductID";
cmd.Parameters.AddWithValue("@ProductID", gvOrderDetails.SelectedRow.Cells[1].Text);
cmd.ExecuteNonQuery();
con.Close();
}
protected void gvOrderDetails_SelectedIndexChanged(object sender, EventArgs e)
{
DeductFromInventory();
}
<?php
$sql = "SELECT * FROM db";
$result = mysqli_query($con, $sql);
while($row= mysqli_fetch_assoc($result)) {
$var = $row['field_name'];
echo $var."<br>";
// Outputs name1 name2 etc.,
}
?>
答案 0 :(得分:0)
在按钮的点击事件中