V
V
Vyacheslav Lebedev2014-04-17 17:24:01
MySQL
Vyacheslav Lebedev, 2014-04-17 17:24:01

MySQL - what type of data to choose for inserting multiple values ​​into a table?

The essence of the problem is that, for example, I leave a review and select several categories of this review.
How to store in the database a selection of several categories for a review?
I searched on my own, found out that there are 2 types of ENUM and SET lists. But they require to be pre-filled in the database when creating a table, and I can add categories and select already added ones, so such data types do not work for me ...
And how will the query be implemented to insert such data through the select multiple field ( html)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stepan, 2014-04-17
@slavikse

I leave a review and select several categories of this review.
How to store in the database a selection of several categories for a review?

Create a linked table that will contain the review id and category.
For example Review of the type "Test review" in the cat1,cat2 category, 2 records will be added to the database
1 cat1
1 cat2
Where 1 is the review id.
Sampling is elementary.
ENUM and SET not absolutely your variant. They are not for lists of values, but for constants.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question