Forum Moderators: coopster

Message Too Old, No Replies

Session array help

I`m stuck for more than a week now

         

ikke

9:47 am on Mar 15, 2005 (gmt 0)

10+ Year Member



I have the following code and now i`m stuck in it. Maybe someone here can help me. I have the following problem.

I maked an session and stored 2 variables in it $item(Product) and $aantal(ammount) when I excecute it I get only the $aantal and the $item variable on my screen I tried now for a week to get more variables stored in the session. For example I have the following output

Aantal Productomschrijving Prijs Boter Extra
12 Kaas
15 Rosbief

Now you can see what i`m missing I want it to be like this:

Aantal Productomschrijving Prijs Boter Extra
12 Kaas 1.25 ja niets
15 Rosbief 2.50 nee Peper

The array looks like this now:

Array ( [Bal gehakt] => 12 [Belegen kaas] => 15 [Verse jus d`orange, 0,25 liter] => 0 [Jonge kaas] => 15 [Cola, blikje] => 0 [Brie] => 2 )

and it`s should look something like this:
Array ( [Bal gehakt] => 12,1.25,ja,niets [Belegen kaas] => 15,2.25,nee,peper [Verse jus d`orange, 0,25 liter] => 0 [Jonge kaas] => 15 [Cola, blikje] => 0 [Brie] => 2 )

I hope this is clear. If you need more info say it

[edited by: coopster at 12:49 pm (utc) on Mar. 15, 2005]
[edit reason] removed irrelevant code [/edit]

wildeyedfrank

10:27 am on Mar 15, 2005 (gmt 0)

10+ Year Member



I had trouble with that too.

It may not be very elegant, but I just stuck everything together with a delimiter between.

That way it is a 1 dimensional array, the key being the item name, price, etc; the value being the qty purchased.

$uniqueitem=$sku.'`'.$uosid.'`'.$opt; //construct the array key

$_SESSION['cart'][$uniqueitem]=$qty;
if($qty=='0')
unset($_SESSION['cart'][$uniqueitem]);

Turbonutter

10:47 am on Mar 15, 2005 (gmt 0)

10+ Year Member



Whenever I have to store cart information I store the user's sessionid in a table.

ikke

11:09 am on Mar 15, 2005 (gmt 0)

10+ Year Member



Thanks I`m now testing it. And about the table and the session id is not very handy i already tried that.

ikke

12:44 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



Thank you,

I`m now on the right track after more than a week fooling around :P. I hope I can take care of the rest myself. If someone want the source tell me I will post it if it works.

Turbonutter

2:10 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



As for baskets in a database, it depends how your session handler is set up. I have a customised database session handler, which makes it very easy to have a basket in the database.

ikke

2:58 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



I like the idea of sessions and the final invoice is going to be in the database. But thanks for the advice.