This is a discussion on question about an declaring array within the PHP Language forums, part of the PHP Programming Forums category; Hello group, I'm trying to implement a shopping cart and currently have a problem as following. First, I will ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello group, I'm trying to implement a shopping cart and currently have a problem as following. First, I will explain. Consider a page as "products.php" This page has a list of products such as: product name price button (for each row) A 8.00 Add_to_Cart button B 8.00 Add_to_Cart button C 12.00 Add_to_Cart button In this page (product.php) : I have wrapped up the "Add to car" button in a form where it takes the product id and category id of the product to a "add2cart.php" using POST method. <form action="addtocart.php" method="post"> <input type="hidden" name="productid" value="<?php echo htmlentities($productid); ?>" /> <input type="hidden" name="categoryid" value="<?php echo htmlentities($selected_category); ?>" /> <input type="submit" value="Add to Cart" /> </form> In add2car.php I have: <?php session_start(); $_SESSION['order'][]= array("order" => array( 'categoryid' => $_POST['categoryid'], 'productid' => $_POST['productid'], 'quantity' => ???? ) ); Ok, the problem is that I don't know how to keep adding added product into the SESSION array or don't know how to append it to pre-existing data in $SESSION[]. Currently, If I add the 2nd item the previous item is replaced. Sometimes user adds product A and then he/she adds it later on and I need to keep track of quantity of a specific added item in cart. 1) is the array declared properly base on what I need? how to append to the array? 2) how to increment the quantify of select product if already exists in the array? Thanks. |
|
|||
|
I think I'd have a quantity field and then do $_SESSION['order'][]= array( 'categoryid' => $_POST['categoryid'], 'productid' => $_POST['productid'], 'quantity' => $_POST['quantity'] ); -- Geoff Berrow 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 http://slipperyhill.co.uk |