dymanic columns in mysql tables?

Posted by fayer on Stack Overflow See other posts from Stack Overflow or by fayer
Published on 2010-05-31T19:32:23Z Indexed on 2010/05/31 19:53 UTC
Read the original article Hit count: 196

Filed under:
|

i want to add dynamic columns in a mysql table.

but i dont know exactly how.

i want to let the user add some columns (fields) in a thread.

eg. let him add a integer field and a value (eg. price: 199) or a string field and a value (eg. name: teddybear).

the user can add as many field/value-pairs as he wants.

i thought i could create a many-to-many table:

thread <-> thread_field <-> field

thread: id, title
thread_field: field_id, thread_id, value
field: id, name

is this a good structure?

but in this way i have to set a specific column type of thread_field.value. either its an integer or a string. i want to have the possibility to have it dymanic, let the user choose.

how can i do this?

thanks!

© Stack Overflow or respective owner

Related posts about mysql

Related posts about database