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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.