我正在開發一些PHP產品的訂購頁面。用戶需要能夠選擇多種類型的產品,因此在HTML表單中需要複選框。是否可以通過HTML表單(複選框)發佈多個「值」?
我已經通過「name」屬性爲複選框建立了一個數組。
我的問題是,我想顯示用戶在確認頁面上選擇的內容,所以我希望這些複選框的「值」最終返回產品名稱和產品價格。至於我可以告訴我要只有一個值被卡住,所以我試圖來解決這個問題:
<?php
//variables for the array and the count
$parray = $_POST['product'];
$pcount = count($parray);
//arrays for each product's information; i've only listed one for simplicity
$br = array("Big Red", 575);
/*The idea for this was for each product ordered to add a line giving the product information and display it. When the $key variable is assigned, it is stored simply as a string, and not an array (yielding [0] as the first letter of the string and [1] as the second), which I expected, but my general idea is to somehow use $key to reference the above product information array, so that it can be displayed here*/
if (!empty($parray))
{
for ($i=0; $i < $pcount; $i++)
{
$key = $parray[i];
echo "<tr><td height='40'></td><td>" . $key[0] . "</td><td>" . $key[1] . "</td></tr>";
}
}
?>
反正讓我的$關鍵變量實際上充當如果它是數組的名稱設置爲? 如果沒有,有沒有什麼好的方法可以做到這一點?
什麼是您的HTML是什麼樣子? – PeeHaa 2012-04-27 17:42:06