0

I have the session $_SESSION['cart_array'] which stores data from my shopping cart, and once var_dumped looks like

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"
   }
}

I think I need to store each column in a variable to be able to parse it to my function then Mysql query. How is this done?

5
  • 1
    Er... The $_SESSION array is a variable, isn't it? Commented Mar 14, 2013 at 12:15
  • Do you mean storing the session data into your database? Commented Mar 14, 2013 at 12:15
  • @ÁlvaroG.Vicario Ok so if I only needed to parse item_id from this array to my function, how is this done? Commented Mar 14, 2013 at 12:16
  • I'm still not sure I get what this question is about. Do you mean that you know how to write arrays but not how to read from them? Commented Mar 14, 2013 at 12:20
  • @ÁlvaroG.Vicario How would I print_r just the price or item_id from that array? Commented Mar 14, 2013 at 12:26

1 Answer 1

2

$_SESSION is an array. Run an foreach() loop.

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

EDIT:

$product_id = $_SESSION['cart_array']['0']['item_id'];
$query2 = mysql_query("INSERT INTO transactionDetails (Order_ID, Product_ID, Price, Quantity) VALUES('{$orderId}', '{$product_id}', '{}', '{}')");
Sign up to request clarification or add additional context in comments.

1 Comment

So if I wanted to put price into a mysql statement such as $query2 = mysql_query("INSERT INTO transactionDetails (Order_ID, Product_ID, Price, Quantity) VALUES('{$orderId}', '{}', '{}', '{}')"); What would I put in the brackets?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.