2013-03-14 88 views
0

我有我從購物車中存儲數據的會話$_SESSION['cart_array'],一旦var_dumped看起來像存儲會話數組變量

array(2) { 
    [0]=>array(3){ 
    ["item_id"]=>string(1) "6" 
    ["quantity"]=>int(1) 
    ["price"]=>string(5) "10.99" 
    } 
    [1]=>array(3) { 
    ["item_id"]=>string(1) "7" 
    ["quantity"]=>int(1) 
    ["price"]=>string(4) "1.99" 
    } 
} 

我想我需要每一列存儲在一個變量能夠解析它給我的函數然後是Mysql查詢。這是如何完成的?

+1

呃......的'$ _SESSION'數組* *是一個變量,不是嗎? – 2013-03-14 12:15:01

+0

您是否將會話數據存儲到數據庫中? – Prisoner 2013-03-14 12:15:34

+0

@ÁlvaroG.Vicario好的,如果我只需要從這個數組中解析item_id到我的函數,這是如何完成的? – jhetheringt7 2013-03-14 12:16:14

回答

2

$_SESSION是一個數組。 運行一個foreach()循環。

echo $_SESSION['cart_array']['0']['item_id']; 

編輯:

$product_id = $_SESSION['cart_array']['0']['item_id']; 
$query2 = mysql_query("INSERT INTO transactionDetails (Order_ID, Product_ID, Price, Quantity) VALUES('{$orderId}', '{$product_id}', '{}', '{}')"); 
+0

所以,如果我想把價格放到一個mysql語句中,如$ query2 = mysql_query(「INSERT INTO'transactionDetails'(Order_ID,Product_ID,Price,Quantity)VALUES('{$ orderId}','{}','{ }','{}')「);我會把什麼放在括號內? – jhetheringt7 2013-03-14 12:36:30

+0

查看編輯答案 – 2013-03-14 12:39:53