我嘗試從我的另一頁的數據打印出來給我的新的一頁,當我點擊提交的cart.php檢索數據輸入到一個新的頁面在PHP
這是我的代碼
cart.php
function paypal_items(){
$num = 0;
foreach ($_SESSION as $name => $value){
if ($value !=0){
if (substr($name, 0, 5) == "cart_"){
$id = substr ($name, 5, strlen($name)-5);
$get = mysql_query ('SELECT id, name, price FROM menu WHERE id='.mysql_real_escape_string((int)$id));
while ($get_row = mysql_fetch_assoc($get)) {
$num++;
echo '<input type="hidden" name="item_number_'.$num.'" value="'.$id.'">';
echo '<input type="hidden" name="item_name_'.$num.'" value="'.$get_row['name'].'">';
echo '<input type="hidden" name="amount_'.$num.'" value="'.$get_row['price'].'">';
echo '<input type="hidden" name="quantity_'.$num.'" value="'.$value.'">';
}
}
}
}
}
function cart() {
$total = 0;
foreach($_SESSION as $name => $value) {
if ($value>0) {
if (substr($name, 0, 5) == 'cart_'){
$id = substr($name, 5, (strlen($name)-5));
$get = mysql_query('SELECT id, name, price FROM menu WHERE id=' .mysql_real_escape_string((int)$id));
while ($get_row = mysql_fetch_assoc($get)){
$sub = $get_row['price'] * $value;
$target_data = $get_row['name'].' x '.$value.' @ $'.number_format($get_row['price'], 2).' = $'.number_format($sub, 2);
$_SESSION['target_data'] = $target_data;
echo $get_row['name'].' x '.$value.' @ $'.number_format($get_row['price'], 2).' = $'.number_format($sub, 2).' <a href="cart.php?remove='.$id.'">[-]</a> <a href="cart.php?add='.$id.'">[+]</a> <a href="cart.php?delete='.$id.'">[Delete]</a><br />' ;
}
}
$total += $sub;
}
}
if ($total == 0){
echo "Your Cart Is Empty";
}
else {
echo "<p>Total : $".number_format($total, 2).'</p>';
<p>
<form action="bill.php" method="post">
<?php paypal_items(); ?>
<input type="submit" value="submit" />
</form>
</p>
}
}
我試圖用這個代碼,我嘗試retrie打印出從功能車()
echo $get_row['name'].' x '.$value.' @ $'.number_format($get_row['price'], 2).' = $'.number_format($sub, 2).' <a href="cart.php?remove='.$id.'">[-]</a> <a href="cart.php?add='.$id.'">[+]</a> <a href="cart.php?delete='.$id.'">[Delete]</a><br />' ;
這個數據已經所有的數據輸入
bill.php
<?php
session_start();
echo $_SESSION['target_data'] .'<br />';
print_r($_POST);
?>
但是,我得到的輸出是一樣(我有兩個數據顯示,當我點擊提交)
Milk Tea x 9 @ $1.99 = $17.91
Array ([item_number_1] => 2 [item_name_1] => Ayam Penyet [amount_1] => 6.99 [quantity_1] => 8 [item_number_2] => 1 [item_name_2] => Milk Tea [amount_2] => 1.99 [quantity_2] => 9)
預期輸出我想就像
Milk Tea x 9 @$1.99 = $17.91
Ayam Penyet x 8 @6.99 = $55.92
有人知道如何解決這個?? ??
感謝:)
如果我正確理解你的問題,你只是想把這個:'Array([it em_number_1] => 2 [item_name_1] => Ayam Penyet [amount_1] => 6.99 [quantity_1] => 8 [item_number_2] => 1 [item_name_2] => Milk Tea [amount_2] => 1.99 [quantity_2] => 9) '入此:'Milk Tea x 9 @ $ 1.99 = $ 17.91 Ayam Penyet x 8 @ 6.99 = $ 55.92'。是對的嗎? – Travesty3
是的......這就是我想要的 –
你知道該怎麼做嗎......我被困在這個問題上超過10個小時......對我來說太糟糕了。 –