SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Update 'total' field with multiple price fields

    ahoy, i am currently developing a cart for a website at my company.
    What i am attempting to do is update the grand total field dynamically as the
    product total (determined by quantity & price) are being populated.

    Each product in the cart is being generated by a foreach (php) reading from a mysql database.

    As the total values are not being prepopulated im not exactly sure what the logic would be to get the desired values.

    I will also mention im relatively new to the whole web development area, i started begining of this year and feel i could still learn alot about the 'logic' of a computer.

    If anything is unclear about what i stated above feel free to request additional information.

    Thanks in advance

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is your cart coded in javascript or php?

    I hope it's in php because if it's in javascript you will probably need a Plan B for those that have javascript turned off in their browsers for whatever reason and besides, a server side cart will be much more secure than a client side cart.

    My suggestion would be to build a shopping cart class.

    The class could include the following

    1) an associative array with the product_id as key and the quantity for that product as the value

    2) an associative array with the product_id as key and the price of the product when it was added to the cart as the value

    3) class method to calculate the total value of the cart from the arrays in 1)

    4) class methods to add/delete/change quantitiies for items in the cart

    5) class method to empty the cart

    6) class methods to retrieve the cart contents for display purposes.

    If you post the code you have so far, it will be easier to help you.

  3. #3
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Kalon, thanks for the speedy and helpfull reply!

    You actually gave me exactly the information i needed - i just really needed the logic, i believe i should look into arrays more in the future

    Your input is much appretiated.


Tags for this Thread

Bookmarks

Posting Permissions

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