Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2004
    Posts
    2

    Unanswered: Calculating dynamic values for shopping cart quantity

    i've got a self-built shopping cart that lists all items in the users cart along with a quantity textfield that the user can type in to update the quantity of each item. i am needing to be able to add together all those quantity textfield values for each item to get a total quantity of items in the cart. for instance...

    a user is able to buy cd A and cd B. they can also specify that they want 1 copy of cd A and 12 copies of cd B. so i would need to add the two quantity textfields together to get a total quantity of 13(needed to calculate shipping).

    how do i acheive this dynamically since the values are being pulled from a database and will change everytime per shopper?

    make sense???????
    - kelly

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    two options: loop over the rows returned from the query that retrieved the cart items, an calculate the total quantity in the loop, or issue a separate query
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Aug 2004
    Posts
    330
    You could do it in a sigle query if you union the detail with the total.

  4. #4
    Join Date
    Nov 2004
    Posts
    2

    thanks

    thanks for the help...i ended up getting the total by using Select SUM(quantity) statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •