D
D
Danil2016-07-27 16:10:00
MySQL
Danil, 2016-07-27 16:10:00

How to store a dynamic number of properties?

There is a product, it can have a different number of properties, and when ordering, the client himself specifies the parameters of these properties (for example: color: black, number of legs: 3, folding: yes, pattern: stripe, etc...) How to store it all? Well, let's say the product is understandable: id_товара, название_свойства. And how to store what users enter?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Evgeny Svirsky, 2016-07-27
@e_svirsky

OneToMany - 2 tables.
linked by onetomany link:
good.id = good_property.good_id

P
Pavel O, 2016-07-27
@gans5131

A stupid, but effective option
to store all parameters in one field of the database as a serialized array

A
Artemy, 2016-07-27
@MetaAbstract

For each property, you need to determine its type and, accordingly, bind the write-read algorithm, interface, and storage system, depending on the type. This problem is generally related to working with metadata and metaalgorithms.

P
Peter, 2016-07-27
@petermzg

Create tables:
1. Property name (id, name, goodid - product)
Example: 222, "Color", 333
2. Possible values ​​(id, propid, value)
Example: 1, 222, Black
2, 222, White
And then that
3. Users will enter: (id, userid, propvalueid, goodid - this field is already redundant)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question