sql - Single or multiple mysql rows? (shopping basket) -
I am currently creating a custom e-commerce site (in php, but this is not really relevant for this question is).
I just got to make a shopping cart, and can not decide between the following 2 options:
Option 1:
Basket table:
In this option, I have a line per user, in all items with Archived items and quantity of
This format is already used in a cookie based basket for non-logged users, so there is no problem parsing the item field.
Option 2:
Basket_items table:
- id
- user
- Item
- Quantity
In this option, I will have one line per line in the basket.
Option 3:
> Suggest a better idea.
Conclusions
Both of my options are equally easy to apply, so the question comes below which the basket is more efficient to update / Will be convenient.
Thanks for any answers, nico
option 2 is the way to go To store all the objects and quantities in the field of objects (option 1) means that you are going against the relational nature of MySQL. You have to define a format and it will have to be parsed with option 1, along with the option you have not written any additional code. In addition, with Option 2, you will be able to easily do other things in line with the line, such as total calculation, shipping amounts, etc. along with reporting on item quantity sold (just a simple question).
Of course, if I was writing this, then I would ask myself if there is a library available - such a general functionality in the shopping cart is not again to the PHP world. , So I do not know what the options are, but I'm sure there should be something that you can reuse. So finally, I encourage you to choose Option 3 - If you avoid it, do not apply it yourself: -)
Comments
Post a Comment