Originally posted by teckniel
how is it don the other way????
Well, one way is with two tables. One contains the user's session id and other user-specific data, the other contains cart items (more exactly, ids of cart items), and includes a field for storing the id of the user who has that item in their cart.
All users use the same two tables.
I sometimes just store the time and date of the last user action as part of the data stored in the user table. Occasionally, I look through the table and find records that are more than (e.g.), a day or so old (older than the session lifetime, anyway) and drop them and any rows in the other table indexed to such "stale" users.
It may not be the most elegant of solutions, but I'd rather have data going stale in the database through lack of use than trash data that someone's still trying to use - and who sits and stares at a shopping cart for days on end without doing anything to it?
Have a look at some of the shopping cart scripts on this site and at Zend to see how others do it.