D_Guy13
D_Guy13

Reputation: 561

Best way to store multi-values in a field

I have a form field that accepts multiple values (Number values between 00-999) that I want to store inside a MySQL field.

What is the best option to go with? (Field type?)

I want to store the data in this format,

1|2|3|4|5|

I want to later query those values and be able to separate them from each other with PHP for mathematical operations.

Upvotes: 0

Views: 72

Answers (1)

sumit
sumit

Reputation: 15464

It is not good idea to store values using glues like commas and pipes. Because later when you need to execute sql and to some mathematical operation , it will be tedious. IMO seperate bridge table will do the task

tables

forms

id, name

form_values

form_id value
1        1
1        2
1        3

you can use group_concat to fetch value as your output and can have calculations easiliy.

Upvotes: 2

Related Questions