简体   繁体   English

我需要用不同的值更新多行数据。 我可以用来实现相同的php循环或代码?

[英]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.

相关问题 我有一个下面的数组,其中一些相同的键具有不同的值。 如何在PHP中将相同的键值与此键组合? 我正在使用WAMP,Codeigniter - I have a below array with some same keys with different values. How can I combine same keys values with that key in PHP? I am using WAMP, Codeigniter 用不同的值更新多行中的同一列 - Update same column on multiple rows with different values 如何优化此功能? 我需要遍历用户,然后遍历用户提交的数据并更新值,这需要1分钟以上的时间 - How can I optimize this function? I need to loop though users, and then loop through user submitted data, and update values, it's taking > 1 minute PHP-如何使用来自两个数组的foreach循环构建网格而不在行中重复值 - PHP - How can I use foreach loop from two arrays to build a grid without repeating values in rows 我如何使用包含数字的php变量在数据库表中创建多个行 - how can i use php variable which contain numbers to create multiple rows in table of database 我如何才能分别更新php查询的几个不同值? - How can I update php query several different values individually? php beginner,我可以为多个循环分配相同的变量 - php beginner, Can I assign same variable for multiple loop 我可以使用相同的键,不同的值来使用多个$ _GET吗? - Can I have multiple $_GET with the same key, different values? 我可以使用不同的键,相同的值使用多个$ _GET吗? - Can I have multiple $_GET with the different key, same values? 如何更新来自php的一系列循环数据? - How can I update series of loop data that come from php?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM