[英]How to save textbox values entered in each row of a dynamic table
I have a dynamic table with 4 textboxes qty, price, discount and subtotal in each row. 我有一个动态表,每行有4个文本框,分别为数量,价格,折扣和小计。 How to get an array with each values entered in each textbox in each row in $_POST?
如何获得一个数组,该数组具有在$ _POST的每一行的每个文本框中输入的每个值? Like this for example:
例如:
[0]=> {
["Price"]=>10
["Qty"]=>5
["Discount"]=>1
["Subtotal"]=>49
}
[1]=> {
["Price"]=>5
["Qty"]=>10
["Discount"]=>2
["Subtotal"]=>48
}
This is my code: 这是我的代码:
<?php
while($iArticles < count($listeArticlePourUnDossier))
{
?>
<tr>
<td><?php echo ($listeArticle[$iArticles]['name']); ?></td>
<td><input type="text" name="Price[]" id="Price"/></td>
<td><input type="text" name="Qty[]" id="Qty" /></td>
<td><input type="text" name="Discount[]" id="Discount" /></td>
<td><input type="text" name="Subtotal[]" id="Subtotal" /></td>
</tr>
<?php
$iArticles++;
}
?>
Thank you 谢谢
Not 100% sure I grasped the true nature of the question and the following has not been tested but will, I hope, be of use - there is no sanity / validity checking of supplied POST data here though 不能100%确定我已掌握问题的真实性质,并且未测试以下内容,但希望可以使用-尽管此处没有对提供的POST数据进行完整性/有效性检查
$prices=$_POST['Price'];
$qtys=$_POST['Qty'];
$discounts=$_POST['Discount'];
$subs=$_POST['Subtotal'];
$data=[];
foreach( $prices as $index => $price ){
$data[]=[
'price' => $price,
'qty' => $qtys[ $index ],
'discount' => $discounts[ $index ],
'subtotal' => $subs[ $index ]
];
}
printf( '<pre>%s</pre>', print_r( $data, true ) );
Make each HTML name an array with an index. 使每个HTML名称成为带有索引的数组。
<?php
$x=0;
while($iArticles < count($listeArticlePourUnDossier))
{
$x++;
?>
<tr>
<td><?php echo ($listeArticle[$iArticles]['name']); ?></td>
<td>
<input type="text" name="Price[<?php echo $x; ?>]" id="Price_<?php echo $x; ?>"/>
<input type="text" name="Qty[<?php echo $x; ?>]" id="Qty_<?php echo $x; ?>" />
<input type="text" name="Discount[<?php echo $x; ?>]" id="Discount_<?php echo $x; ?>" />
<input type="text" name="Subtotal[<?php echo $x; ?>]" id="Subtotal_<?php echo $x; ?>" />
</td>
</tr>
<?php
$iArticles++;
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.