使用數組作爲輸入字段名.. 像數量[0],數量[1] ...數量[10]等... 然後使用foreach來處理傳入的$ _POST數組...
這裏是如何實現大量的行和列。
<form method="post">
<table>
<?
$rows=10;
$cols=3;
$colsArr = array();
$colsArr[0] = "qty";
$colsArr[1] = "desc";
$colsArr[2] = "unitprice";
for($i=0;$i<$rows;$i++)
{
echo "<tr>";
for($j=0;$j<$cols;$j++)
{
$name = $colsArr[$j];
echo "<td><input type=text name=".$name."[" . $i ."]></td>";
}
echo "</tr>";
}
?>
</table>
<input type="submit">
</form>
看看這段代碼的輸出源代碼。 當你發佈這樣的形式,你會得到: (我張貼3個項目與數量,1,3,5與描述DESC1,DESC2,desc3和價格$ 1.00,$ 2.00,$ 5.00)
Array ([qty] => Array ([0] => 1 [1] => 3 [2] => 5 [3] => [4] => [5] => [6] => [7] => [8] => [9] =>) [desc] => Array ([0] => desc1 [1] => desc2 [2] => desc3 [3] => [4] => [5] => [6] => [7] => [8] => [9] =>) [unitprice] => Array ([0] => 1.00$ [1] => 2.00$ [2] => 5.00$ [3] => [4] => [5] => [6] => [7] => [8] => [9] =>))
還有一個錯字:「a from」 – Jocelyn 2012-08-14 23:14:46