Hmm, I'm still not entirely clear on the options. Are those options generic, i.e. the same options exists for all products, or do each product have their own set of options? I'll assume it is the latter
First off, to deal with many-to-many relation, n:m, for tables a and b, you need an extra table x. The result is a 1:n relation from a to x, and an n:1 relation from x to b.
To know what options are available for a specific product
CREATE TABLE productOption (
productID INT UNSIGNED,
optionID INT UNSIGNED,
PRIMARY KEY(productID, optionID),
FOREIGN KEY(productID) REFERENCES Product(id),
FOREIGN KEY(optionID REFERENCS Option(id)
);
Product
id name
1 iron bat
2 aluminum bat
Option
id size weight ...
1 L 50
2 L 2
3 S 25
4 S 1
ProductOption
productID optionID
1 1
1 3
2 2
2 4
Thus, valid options for the light weight aluminum bat are options 2 and 4. When the user is presented options to select from you need something like
SELECT product.id, option.*
FROM product
INNER JOIN productOption ON product.id = productOption.productID
INNER JOIN option ON option.id = productOption.optionID
This will get you all options for each and every product. You can of course append "WHERE product.id = 2" to get only options for the aluminum bat.
To deal with the selected option for a product in the actual order, things are simpler 🙂
All you need in orderContent is orderID, productID and optionID (for this purose. the other things should of course still remain in this table). But, since it is possible that I want to order the aluminum bat in both large and small size in the same order, you need to have a primary key on all these columns in orderContent, instead of just on orderID and productID:
PRIMARY KEY(orderID, productID, optionID)