I need to create a dynamic HTML form using PHP. I am only considering the following fields : Text, Text box, Radio, Check Box, Drop down.
I am thinking of the creating the following database design.
Field ID | Field Type | --- Other Attributes, such as length and others --- | Values.
In the above table, the "Values" means the values for checkbox (or any form element with multiple values) in a comma separated type.
Example :
Table : Fields
Field ID | Field title | Field Type | --- Other Attributes, such as length and others --- | Values.
1 | Name | Text | |
2 | Color | Checkbox | | Blue,Red,Pink
3 | Gender | Radio | | Male,Female
I could then query the above table and generate HTML accordingly, getting the values using explode function.
The other possible design that I could think off is :
Table : Fields
Field ID | Field title | Field Type | --- Other Attributes, such as length and others ---
1 | Name | Text |
2 | Color | Checkbox |
3 | Gender | Radio |
Table : Fields_options
Field ID | Value
2 | Blue
2 | Red
2 | Pink
3 | Male
3 | Female
I could then query the above database the generate the HTML accordingly.
In the first approach, I have the overhead of parsing the values and comma separating it. In the second approach, I have the overhead of the second query with a where clause. Which one would be better and why? Is there any better approach?