我有这样的表格:
<form method="post" action="mypage.php" orderform="" name="" id="orderform">
<a id="add">+</a>
<table width="533" cellspacing="0" cellpadding="2" border="0" id="ordertable">
<tbody>
<tr>
<td width="33%">Product Code (e.g 66203)</td>
<td width="33%">mtrs sq Required (e.g 10)</td>
<td width="33%">Preview Image</td>
</tr>
<tr class="item">
<td class="prodcode "><input type="text" id="prodcode[]" name="prodcode[]" class=" "></td>
<td class="meterage"><input type="text" id="meterage[]" name="meterage[]"></td>
<td class="imgsample"></td>
</tr>
<tr class="item">
<td class="prodcode "><input type="text" id="prodcode[]" name="prodcode[]" class=" "></td>
<td class="meterage"><input type="text" id="meterage[]" name="meterage[]"></td>
<td class="imgsample"></td>
</tr>
</tbody>
</table>
<button>Submit</button>
</form>
我正在尝试接收帖子并用其计量打印副产品价值......如下所示(这似乎只返回最后的结果)任何想法?
$number_of_products=count($_POST['prodcode']);
for ( $i=0; $i<$number_of_products; $i++){
$orderdetails = $_POST['prodcode'][$i]." has the meterage: ".$_POST['meterage'][$i]."<br/>";
}
答案 0 :(得分:3)
每次运行for循环时,你都会覆盖$ orderdetails的内容。
尝试这样的事情:
$number_of_products=count($_POST['prodcode']);
$orderdetails = "<h1>Order Details</h1>";
for ( $i=0; $i<$number_of_products; $i++){
$orderdetails .= $_POST['prodcode'][$i]." has the meterage: ".$_POST['meterage'][$i]."<br/>";
}
答案 1 :(得分:0)
尝试为输入字段上的prodcode[]
和meterage[]
名称编制索引,即:
<form method="post" action="mypage.php" orderform="" name="" id="orderform">
<a id="add">+</a>
<table width="533" cellspacing="0" cellpadding="2" border="0" id="ordertable">
<tbody>
<tr>
<td width="33%">Product Code (e.g 66203)</td>
<td width="33%">mtrs sq Required (e.g 10)</td>
<td width="33%">Preview Image</td>
</tr>
<tr class="item">
<td class="prodcode "><input type="text" id="prodcode_0" name="prodcode[0]" class=" "></td>
<td class="meterage"><input type="text" id="meterage_0" name="meterage[0]"></td>
<td class="imgsample"></td>
</tr>
<tr class="item">
<td class="prodcode "><input type="text" id="prodcode_1" name="prodcode[1]" class=" "></td>
<td class="meterage"><input type="text" id="meterage_1" name="meterage[1]"></td>
<td class="imgsample"></td>
</tr>
</tbody>
</table>
<button>Submit</button>
</form>
答案 2 :(得分:0)
因为你每次都会覆盖它 更改 $ orderdetails = 至 $ orderdetails。=