Problem with shopping cart (session)
I store item_id and qty into an array ($_SESSION[item_id] & $_SESSION[qty]), but I have a big problem.
When I add the first item and trying to add one more, the second one deletes the first and takes its place.
Please tell me some suggestions to solve this problem! SOS!!!
Re: Problem with shopping cart (session)
The reason why isbecuase you are not making them arrays. Why you add an item use this method:
PHP Code:
<?php
function add_item($new_itemid, $new_qty)
{
$_SESSION['itemid'][] = $new_itemid;
$_SESSION['qty'][] = $new_qty;
}
?>
I would suggest you change your approach and have an array of item objects like this:
PHP Code:
class Item
{
var $id;
var $price;
var $qty;
function Item($id, $price, $qty)
{
$this->id = $id;
$this->price = $price;
$this->qty = $qty;
}
}
function add_item(& $item)
{
$_SESSION['cart_items'][] = & $item;
}
/* example */
$item = new Item('Mars Bar', 0.55, 2);
add_item($item);
Re: Problem with shopping cart (session)
visualAD:
can you post the full code?
I'm stuck...
:)
Re: Problem with shopping cart (session)
I haven't got full code. I just made that out of my head. What is it you are stuck on?
Re: Problem with shopping cart (session)