on 5/5/05 2:52 AM, Jigal van Hemert at jigal@stripped wrote:
> ----- Original Message -----
> From: "Scott Haneda"
>> on 5/5/05 2:11 AM, Joerg Bruehe at joerg@stripped wrote:
>> Basically, I have a chopping cart, this one is a little weird, for reasons
>> not worth explaining, you have a cart when a user is not logged in, and
> they
>> *may* have one they made at some point when logged in. There is a chance
>> the logged in cart already has stuff in the non logged in cart, I don't
> want
>> duplicate items in the cart, so I want to just get rid of the oldest one.
>
> I'd add a UNIQUE index on user id and product id (beware of the handling of
> NULL values!) and use REPLACE to add the new data.
> "REPLACE works exactly like INSERT, except that if an old record in the
> table has the same value as a new record for a PRIMARY KEY or a UNIQUE
> index, the old record is deleted before the new record is inserted."
> http://dev.mysql.com/doc/mysql/en/replace.html
Cant, at least not how this mess of a site has to work.
If a user is not logged in, there has to be the ability to add to a cart,
all I have is a session id from the cookie, they are not logged in. so
these are inserts into a cart table. Sure, I can prevent the duplicates for
that session, but there comes a point where they log in. While the chances
are slim, when they login, there may be a existing cart already in place for
that user. So I am not inserting anything at that point, but updating old
logged in cart items to the non logged in new ones. Its just a setting of
the user_id in a update statement where session is either old or new. This
collects the records to the users account, but, there is that rare case
where they may have ended up with 2 of the same product in the cart.
--
-------------------------------------------------------------
Scott Haneda Tel: 415.898.2602
<http://www.newgeo.com> Novato, CA U.S.A.