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
My suggestion would be to build a shopping cart class.
The class could include the following
an associative array with the product_id as key and the quantity for that product as the value
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
class method to calculate the total value of the cart from the arrays in 1)
class methods to add/delete/change quantitiies for items in the cart
class method to empty the cart
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.
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:rolleyes:
Your input is much appretiated.