[thelist] updating db after user alters shopping basket amounts

Dunstan Orchard dunstan at 1976design.com
Thu Oct 24 03:53:00 CDT 2002

Hey rudy,

> > If I print out a list of items in a user's shopping cart and
> > allow him to update the amount of each item he wants,
> > how can I write this back into the database?
> hi dustan
> you have to loop through the individual form fields and update each
> orderitem record in turn
> this presupposes that the correct primary key values are in form fields
> somehow, e.g. <input type="text" name="qty78">

would that be the id of the row in the shopping cart that contains the image
in question? and if I have four form fields on each row, they can't all be
named for the primary key can they?

> the customer's cart (i.e. order) is related to the products being
> purchased in a many-to-many relationship, implemented through an
> association or junction table for the items ordered
>    order ---1-to-many --- orderitem --- many-to-1 --- product
> when dealing with a customer order(cart), there's one row of the order
> table, linked to multiple rows of the orderitem table -- actually, i guess
> i should say that all the orderitem rows are linked to the one order
> row, because the order (cart) id is a foreign key in the orderitem table

I don't think my tales are set up like that.
I just have one table for the shopping cart - I don't think I need more?

> > If it was just one item then on submission of the form
> > I'd just update where $productId = productId, but how do
> > you do that when you never know how many items he might
> > have in the cart?
> you have to loop through all the orderitems with the same cart (order)
> id
> > http://www.1976design.com/testarea/example.gif
> hmmm...
> the first thing that suggests itself is that image quality (AA4, A3,
> etc.) is an attribute of the orderitem table, and not the product (the
> image)... and yet i could order 3 of one size and 2 of another size,
> so that would strongly suggest separate rows in the orderitem table...

there is an image table that contains the image's id, its title, the date it
was photographed, the height and width of the files, the amount of times it
was viewed, etc.

there is also a lightbox table that contains a lightbox id, the users id, and
the image id.

then there is the shopping cart table which contains the cart id, the users
id, the image id, A4 quantity, A3 quantity, other print size value and license

there's a seperate row for each image in each user's cart, pretty much exactly
as it's mirrored in the table you saw.

> and as for updating, what if i had a quantity of 1 and i set it to 0?
> do i have to hit the red "-cart" link to remove?  what should the
> program do? update the quantity to 0?  what if i still want 2 if the
> other size? what if i only wanted one image of oe qualtiy and set it
> to zero?  you'd want to do a delete then for sure...
> i guess that form is not very intuitive for me as a user, but i can
> see how to build the update statements from it

the checkout page presents all the images the user has decided they want to
buy, it's then up to them to choose in what form they want the image to be
delivered to them. If the A4 and 43 print boxes contain value 0 on submission
then one of the tick boxes must be ticked (ie. if they don't want a print at
either of those sizes they must want the image printed at a different size or
to license the image and receive it digitally).

if all values for one image are set to 0 and/or unticked, then the user would
get an alert on submission asking them to m ake a choice or remove the image
from their cart.

It would probably make more sense if you had followed the process through and
not just seen the final stage screen grab.

does that make things a bit clearer?

thanks very much for the help... still puzzled though :o/

cheers - dunstan

Dorset, England

More information about the thelist mailing list