0
我有一個while循環創建表單,什麼,我想用戶所要做的就是輸入一個號碼下一個他們想要的項目,提交後,將提交他們輸入的數字加上我提供的變量(沒有他們看到變量)。這可能嗎? php正在循環訪問文本文件,輸出每行作爲用戶的選項。HTML文本輸入發送一個PHP變量以及用戶的輸入
while(($line = fgets($filehandle)) !== false){
$itemParts = explode(" - ",$line);
$item = $itemParts[0];
$price = $itemParts[1];
echo "<input type='text' name='hardware[]' value='{$item}-|-{$price}'>£".$price." ".$item."<br />";
}
在生成的頁面上,我循環訪問hardware []數組以向用戶顯示其選擇以及更新數據庫。
foreach ($_POST['hardware'] as $itemWanted){
$itemParts = explode('-|-',$itemWanted);
$item = $itemParts[0];
$cost = $itemParts[1];
echo $item.' £'.$cost.'<br />';
$total += $cost;
$allHardware .= "**".$item." - GBP ".$cost;
}
我可能會用錯誤的方式去做,但有人知道如果這可能與未知數量的文本文件和項目?我目前的工作方式是,有一個複選框而不是文本框,這一切工作正常,但現在我需要的用戶選擇他們所需要的量。
while(($line = fgets($filehandle)) !== false){
$itemParts = explode(" - ",$line);
$item = $itemParts[0];
$price = $itemParts[1];
echo "<input type='checkbox' name='hardware[]' value='{$item}-|-{$price}'><font size='2'>£".$price." ".$item."</font><br />";
}
預先感謝任何幫助
太感謝你了多個行,完美的作品 – Maff
我很高興 - 享受:) –