Jump to content

small, medium, large with quantities


phppup

Recommended Posts

As long as I'm logged in (although this may be more to the topic of 'table structure'), my table has fields for small, medium, and large blue candles and small, medium, and large pink candles.

When an order is placed, the quantity requested is INSERTED into the correct field.

 

Am I creating unnecessary overhead?

 

Is there a way to have just one field for blue candles and one for pink, whereby the INSERT will record a customer request for 4 candles that are the small size?  And how would I retrieve the data when I want to know both the total number of candles and their sizes.

 

Note: the order form has radio buttons for the sizes, so a single order can only accept a single size per submission.  Not sure if there's a simple way around that, but I'm learning more each day.

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/257216-small-medium-large-with-quantities/
Share on other sites

How about this structure?

orders

order_id | ...
---------+----
       1 |
       2 |
       3 |

products

product_id | color | size   | ...
-----------+-------+--------+----
         1 | blue  | small  |
         2 | blue  | medium |
         3 | blue  | large  |
         4 | pink  | small  |
         5 | pink  | medium |
         6 | pink  | large  |

orders_products

order_id | product_id | quantity | ...
---------+------------+----------+----
       1 |          1 |        3 |
       1 |          3 |        3 |
       2 |          2 |        5 |
       2 |          5 |        5 |

That's a fairly typical setup for this kind of thing.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.