[英]How to save textbox values entered in each row of a dynamic table
我有一個動態表,每行有4個文本框,分別為數量,價格,折扣和小計。 如何獲得一個數組,該數組具有在$ _POST的每一行的每個文本框中輸入的每個值? 例如:
[0]=> {
["Price"]=>10
["Qty"]=>5
["Discount"]=>1
["Subtotal"]=>49
}
[1]=> {
["Price"]=>5
["Qty"]=>10
["Discount"]=>2
["Subtotal"]=>48
}
這是我的代碼:
<?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++;
}
?>
謝謝
不能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 ) );
使每個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.