[英]I need to update multiple rows of data with different values. which php loop or code i can use to implement the same?
I need to update multiple rows of data with different values. 我需要用不同的值更新多行数据。 which php loop or code i can use to implement the same?
我可以用来实现相同的php循环或代码?
here is the code which am using. 这是正在使用的代码。
for ( $i = 0 ; $i < count ( $_POST ['productname'] ) ; $i++ )
{
$qry2 = "UPDATE invoice_transaction
SET inv_trans_item_qty='".$_POST['quantity'][$i].
"',inv_trans_created_by='".$act_admin.
"',inv_trans_created_on='".$date.
"' WHERE inv_code='".$inv_code."'";
$res2 = mysqli_query($cn,$qry2);
}
You can use form elements with names like item[1][productname]
: 您可以使用名称为
item[1][productname]
表单元素:
<input type="text" name="item[1][productname]" />
<input type="text" name="item[1][quantity]" />
<br/>
<input type="text" name="item[2][productname]" />
<input type="text" name="item[2][quantity]" />
Then on the server side you can loop over those arrays: 然后在服务器端,您可以遍历这些数组:
foreach ($_POST["item"] as $item)
{
$productname = $item['productname'];
$quantity = $item['quantity'];
// do stuff with $productname and $quantity
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.