473,513 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

session cart remove

Hi

I hope someone out there can help me.

Im developing a sessionbased shoppingcart. When adding something in
the cxart I do:
session_start();
$_SESSION["cart"][]=array("artnr" => $_GET["artnr"],
"nr" => $_GET["nr"],
"price" => $_GET["price"],
"colors" => $_GET["colors"]
);
It works fine. BUT, when I want to remove one of these element in the
cart: how should I proceed? I have read many post but dindnt find one
suitable to my case.

Thanks

Paolo
Jul 17 '05 #1
5 2697
*** paolo wrote/escribió (19 May 2004 04:28:10 -0700):
$_SESSION["cart"][]=array(...);
It works fine. BUT, when I want to remove one of these element in the
cart: how should I proceed? I have read many post but dindnt find one
suitable to my case.


Maybe you could provide an index number for the array:

$_SESSION['cart_top']++;
$_SESSION["cart"][$_SESSION['cart_top']]=array(...);

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #2
unset($_SESSION['cart'][$some_index]);

to be able to get the correct value for $some_index, an idea is to have each
item in your store be assigned an ID from the database that they're in
(supposing you're using one). Then have $some_index be that ID, so that you
can remove the right item from the cart when you want to.

- JP

"paolo" <pa*********@hotmail.com> wrote in message
news:f9*************************@posting.google.co m...
Hi

I hope someone out there can help me.

Im developing a sessionbased shoppingcart. When adding something in
the cxart I do:
session_start();
$_SESSION["cart"][]=array("artnr" => $_GET["artnr"],
"nr" => $_GET["nr"],
"price" => $_GET["price"],
"colors" => $_GET["colors"]
);
It works fine. BUT, when I want to remove one of these element in the
cart: how should I proceed? I have read many post but dindnt find one
suitable to my case.

Thanks

Paolo

Jul 17 '05 #3
Yes, buit what do you do when you iterate?
Say that $_SESSION['cart_top'] has become 5.
Now you need to remove $_SESSION["cart"][3]
Then you do unset($_SESSION["cart"][3]) I guess?
What happens now? cart_top is still 5. So when you iterate
$_SESSION["cart"][3] will fail, doesnt it?

Paolo
Jul 17 '05 #4
IS not the same problem with your solution?
I do like this now:
$_SESSION["counter"]==null ? $_SESSION["counter"]=0 :
$_SESSION["counter"]++;

$_SESSION["cart"][$_SESSION["counter"]]=array(
"artnr" => $_GET["nr"],
"price" => $_GET["price"],
"colors" => $_GET["colors"]
);
Jul 17 '05 #5
*** paolooracle wrote/escribió (Wed, 19 May 2004 15:04:07 GMT):
What happens now? cart_top is still 5. So when you iterate
$_SESSION["cart"][3] will fail, doesnt it?


foreach($_SESSION["cart"] as $index){
...
}

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
5049
by: David Lozzi | last post by:
Hello All, I am having an issue with thus far one computer on my client's web site. If the user loads the shopping cart and then closes all browser windows, then opens them back up, goes back to...
7
3004
by: Seth | last post by:
I have noticed that the id of my session object changes when I switch from a non-secure to a secure connection. What I'm trying to do: I have a cookie that is built on the non-secure side of...
2
6155
by: Joe Molloy | last post by:
Hi, This isn't a mission critical question but I thought I'dl throw it out there for your feedback as it's a bit curious. I have developed a shopping cart for an application I'm working on...
1
3201
by: Adil Akram | last post by:
I have created a site shopping cart in ASP.net. I am using ASP session object's SessionID on non SSL connection to track session. While adding products to cart DB I insert product and SessionID...
5
3163
by: TRB_NV | last post by:
I'm losing information from my Session when I change pages or start the same page over again. I simplified the code so the example is really clear. The sample code that follows is supposed to...
6
16015
by: KevinGravelle | last post by:
What is wrong with this picture? I'm trying to set my shopping cart text on my home page using the following function that is executed when the class is constructed: protected string...
0
2459
by: TRB_NV | last post by:
I'd been using an Access database based shopping cart, but wanted to change it so that it would use session variables. I have a form that's submitted to a page called addtocart.asp that contains...
4
3730
by: Nick Gilbert | last post by:
Hi, Is it possible to access the Session of an arbitary user from an aspx page? On an e-commerce site, I am notified of payment success via a callback from the payment server to an ASPX page...
1
1501
by: chrism | last post by:
Thanks a lot for the detailed reply, Jerry. As I was trying out your suggestion, I noticed a flaw in my code: Towards the top of the page, before any processing, I set: $cart = $_SESSION; So, I...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5089
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1596
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.