Not sure which forum this belongs in, mysql or php but I'm leaning more towards PHP due to the fact that I have to massage the data and make sure it displays correctly.
We're rebuilding our shopping cart and based on some open source code we found online, my colleague and I started to hack it to pieces so that it fits into our environment. I lost the fight of keeping vital information in the same table as the parent item but he wants to separate them. For example, for each item, there's a shipping cost and a warranty cost associate with EACH item. Instead, he moved these two items out of the table and created a parent-child table. So Product A (id of 100) is associated with Warranty A (id of 200). To make it more complicated, the products table lists everything including each product, warranty code and shipping codes. Instead of a simple query and while loop to display the results, I'm forced to write JOIN queries. It's fine but I'm lost and I'm ending up making multiple calls to the DB.
Table Products
product_id (unique ID of warranty code, product and shipping code)
product_desc
price
Table products_item
parent_id (ID of the product i.e. Widget A0
child_id (ID of the warranty i.e. 2 yrs warranty)
table order_item
order_id
product_id
quantity
table orders
order_id
person_first_name
person_last_name
So basically if I wanted to display an order summary of what a customer orders I would do the following.
select person_first_name, person_last_name, order_id, product_desc from orders a, order_item b, products c where a.order_id = b.order_id AND b.product_id = c.product_id
Now that gives me the person's name, the order ID and the product they ordered. Now how the heck do I pull the warranty info and shipping code relevant to this particular product?