Not understanding th coding/logic behind an "Item Cart"

I’m having difficulties understanding what coding is required to make on of those shopping carts, where you search item, select the add to cart button and it will appear on a cart beside you and it will calculate values (price, weight, shipping cost) as you add.

What I’m trying to make:

So I’m not exactly building a shopping cart, but rather something similar for chemistry. So pretend that the ‘products’ are beakers, each containing different elements (carbon, oxygen, barium, chloride etc… at different quantities) and each beaker’s content has a physical state (gas, liquid, solid).

To do an experiment the user has to select one gas, one liquid and one solid beaker (so 3 in total) this is referred to as their ‘set up’ or the cart if you like.

When a beaker is added, it would display in a table all the contents and quantity of the beaker. Add another beaker and it would do the same, add all the contents to that list BUT check for elements that have been already there (if so just increase its quantity accordingly).

Lastly a button that submits this set up to the database (validation for matching set ups would be required).

Anyone brave enough to take a stab at the HTML/PHP? I need some ideas.

(Note: This is just a very simplified version of what I’m building, so ignore the chemistry)

ok, it sounds like you need a class file to represent a beaker.

the beaker class then has properties associated with it that represent the beaker’s contents.

each time you need a new beaker, you create a new instance of the beaker class.

But the first thing you need to do is design your database. until you have your database built you can’t do much else because all your other code effectively sits on top of the database. the last thing you want is to get half way through your coding and then realise your database model is wrong.

can you post an ERD of your database or at least a listing of the table structures.

think of your database as being analogous to the foundations of a house.

Cheers Kalon. Okay my database: (forgot to add, each beaker can contain a maximum of 4 elements)

Table: Beaker (ID, Name, Weight, Element1, Element1Amount, Element2, Element2Amount, Element3, Element3Amount, Element4, Element4Amount)

That’s all I have for now, I’ve gotten the search form to work without a problem.

Now… to design the table that houses all the set ups:

Table: SetUp (ID, Gas, Liquid, Solid)

Above are the most basic fields required. User contributions are anonymous (it for a classroom of 15 people anyways). I’d like to also introduce a tagging system, that categorizes each set up but that can wait till later.

My database doesn’t get any complicated than this I guess. I will try to come up with some code for the html side after dinner.

in your first post you refered to “users”.

so will each user have their own set of beakers in the database?

if yes, I assume you have a users table and if you want to group beakers by user in the database you will need a foreign key in the beakers table for each beaker linking it to its owner in the users table.

it’s up to you, but I would suggest you get your database set up correctly first before starting on any html code.