I have a form that dynamically generates elements in groups, so I cannot be sure how many things I’m going to submit to the database everytime someone submits a form.
Form
-name
-age
-incident (0)
-incident description (0)
-incident (1)
-incident description (1)
-incident (2....)
-incident descritpion (2....)
and there are about 10 possible dynamically generated form element groups, so I was thinking I would make one table for the entire form, and one table each for the dynamically generated element groups in order.
formdata
name varchar(30)
age int(2)
incident0 sql
incdient1 sql
is that possible?
or is there a different way besides creating a whole bunch of columns in my table that i rarely use?
and if i create a whole bunch of columns would there be memory waste or would it not make a difference if theres not a lot of data submitted in those columns?
The answer you seek is called schema normalization, and it is the quintessential feature of relational database management systems. The Particular concept is called a “one-to-many” relationship, where you have one “form” related to many incidents. This is accomplished by having one table just for incidents, and one of the columns in that table is a numeric reference to an id column in your forms table, thus each incident “knows” which form it belongs to.
Then the SQL can optionally use a join clause when selecting: