我正在做一些學習PHP和和使用smarty來幫助它的HTML。 我試圖建立一個非常簡單的商店一樣的購物車圖像列表,當它被點擊時,它應該通過表單返回我想從該商品獲取的信息,但我無法獲得正確的商品索引....如何在html/php表單中動態訪問數組表單位置?
這是相對於內部TLP循環中的代碼(它是內部使用的smarty一個HTML):
{section name=i loop=$homeList}
<div class="homemenu" align="right">
<table class="menhome" border="0">
<tr>
<td width="102"><img src="{$homeList[i].img}"/></td>
<td width="150">{$homeList[i].Nome} </td>
<td width="350">{$homeList[i].Descricao}</td>
<td width="80">{$homeList[i].Preco} €</td>
<td width="80">{$homeList[i].Disponiblidade}</td>
<td><form action="updatecart.php" method="POST">
<input type="hidden" name="usr[]" value="abobora">
<input type="hidden" name="iditem[]" value="{$homeList[i].IDItem}">
<input type="hidden" name="qta" value="1">
<input type="hidden" name="index" value="1">
<input type="image" name="submit" src="../images/carro.png" width="52" height="52">
</td>
</tr>
</table>
</div>
{/section}
,這是相對於「實驗」的PHP更新代碼:
require_once("functions.php");
var_dump($_POST);
並且這是一個樣本var_dump輸出:
array
'usr' =>
array
0 => string 'abobora' (length=7)
1 => string 'abobora' (length=7)
2 => string 'abobora' (length=7)
3 => string 'abobora' (length=7)
4 => string 'abobora' (length=7)
'iditem' =>
array
0 => string 'it10' (length=4)
1 => string 'it13' (length=4)
2 => string 'it2' (length=3)
3 => string 'it20' (length=4)
4 => string 'it21' (length=4)
'qta' => string '1' (length=1)
'index' => string '1' (length=1)
'submit_x' => string '22' (length=2)
'submit_y' => string '27' (length=2)
的事情是:我怎麼告訴了形式單一的按鈕有一個奇異指數的陣列,並獲得該陣列內的正確的信息訪問?
PS:指數=「1」在這裏只是一個實驗值,我想有相對於指數
PSS的信息是:對不起,壞的輸出格式,但有些時候,我只是不明白的代碼標籤的工作原理....
代碼標籤幫助 - 我只是強調所有的代碼,然後單擊看起來像這樣{}工具欄上的按鈕...只是FYI – 2011-06-10 22:46:32
@dqhendricks因爲有人告訴....它不是我的選擇 – John 2011-06-10 22:49:47