CREATE TABLE product (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(),
other generic stuff specific for this product
)
CREATE TABLE size (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
product_id, INT UNSIGNED,
size VARCHAR(),
FOREIGN KEY (product_id) REFERENCES product(id)
)
CREATE TABLE color (
as above
)
CREATE TABLE stock (
product_id,
color_id,
size_id,
units INT UNSIGNED,
PRIMARY KEY(product_id, color_id, size_id)
)
If the price is dependt on the product alone, then price goes into the product table. If the price depends on the product's size, it goes into the size table.
// Using a prepared statement, your update would look like something like this
$qry = "UPDATE stock Set units = units - 1
WHERE product_id = ? AND color_id = ? AND size_id = ?";
// otherwise you might
$qry = sprintf("UPDATE stock Set units = units - 1
WHERE product_id = %d AND color_id = %d AND size_id = %d", $prod, $color, $size);
To get all products with sizes and colors, as well as the amount in stock
SELECT p.id, p.name, c.color, s.size, stock.units
FROM product AS p
INNER JOIN color AS c ON p.id = c.product_id
INNER JOIN size AS s ON p.id = s.product_id
INNER JOIN stock ON p.id = stock.product_id AND c.id = stock.color_id AND s.id = stock.size_id