I am creating an ecommerce app. I cannot find a way to store quantity of different sizes of the same product. Suppose I have at shirt which has 3 sizes available xl,xxl,xxxl with quantity 20 , 25 , 30 . Now how can I store this into the MySQL table ?
One way I was thinking to do this as to create a String like xl+20,xxl+25,xxxl+30 and store it into a column and I can break this String at "," and "+" while retrieving it but I don't think it is a good idea .
Is there any other better way to do this ?
You can break the same product into separate lines for each size, which is scalable in case you want to add or remove things in the future.
id(pk), product_id, size , quantity
1, 100, xl, 20
2, 100, xxl, 25
3, 100, xxxl ,30
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.