I have two tables. 1.Products 2. Combo
Product Table has column like (product_id, product_name).
Combo Table has column like (combo_id, combo_name, combo_included_products /* combo might have 2 or more products from product table*/)
Rule: 1 Combo can have many products.
Product Table
product_id product_name
1 Pen
2 Pencil
3 Pen Holders
4 Sharpeners
-
Combo Table
combo_id combo_name this_combo_includes_below_products
1 Big_combo (1,2,3,4) => big combo includes all products
2 Small_combo (2,4) => this combo only includes product 2,4
3 test_combo (1,2)
4 Other_combo (1,4)
So How can I insert multiple products ids in third column of combo table?
I am thinking to store data like 1,2,3,4 and 2,4 and so on. Then problem will be to write join query. i.e
select combo.combo_id, combo.combo_name, product.product.id from combo join product ON combo.this_combo_included_products_id = product.product_id <= As there will be multiple product ids, It will not possible.
I am also thinking make a script where I will first fetch combo table as it is, then I will split third cloumn by "," and will run iterate (select * from combo where product id=this_combo_included_item_id[i]) <= I am not sure this is good idea however this can be a alternate solution which require some coding afterwards. (I use phpmysql to fetch data anyways - so I can process that after fetching.)
$sql = "SELECT * FROM combo";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
// I can run other query here
$child_query = "select combo.combo_id, combo.combo_name, product.product.id from combo join product
ON combo.this_combo_included_products_id = product.product_id";
}
However Is there anything else I can do while designing Database table. Thanks.