[thelist] updating db after user alters shopping basket amounts

rudy r937 at interlog.com
Wed Oct 23 19:37:01 CDT 2002

> 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">

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

> 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


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...

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


More information about the thelist mailing list