I've got a pretty large form that includes radio buttons/checkboxes in addition to text inputs. Because of the character of checkboxes, when they publish the shape without checking it, it is not submitted the Publish data. Which leaves me a little tied to how to deal with it.
I initially began my database using the standard 'column for every field'. For instance:
id | userid | firstname | lastname | middlename | phonenumber | mobilenumber |
That rapidly transformed after i wound up getting up to 30 posts. This type is big. I have made the decision I'll make use of an 'EAV schema' to provide my table only 4 rows. It now appears like so:
id | userid | name | value ---+--------+-----------+------ 1 | 1 | firstname | steve ---+--------+-----------+------ 2 | 1 | lastname | blah
This appears just like a better approach.
So my real question is, how must i handle the database when I am unsure of what is going on inside it? Basically have 20 checkboxes (each using their own title), must i by hand see if each was posted and hang a 'null' value otherwise?
Must I empty all of the rows in the table for that user's ID and change it with the new data?
What's a competent method of carrying this out?
EAV is definitely an anti-pattern within this situation. You'll finish track of very convoluted logic simply to retrieve just one group of data.
The first approach is much more maintainable and understandable to others.
If this involves a boolean value, like a checkbox value, I'd use a little/boolean area within the database, in which a check mark will be a true cheap you did not have it published back would be a false.
Exactly the same factor means the EAV schema - have them all within the DB, just mark the worthiness as true or false, based on that which was published.
You need to parse your input first, and see proper values for every item. Then you definitely go ahead and take data and make the database.
The code shouldn't depend around the existance of fields within the form to determine which fields to set up the database. An application may be easily altered, so it may be accustomed to change any area within the table, not only those akin to the fields that you devote the shape.
The EAV schema is nice for those who have lots of similar fields, or perhaps a dynamic group of fields. Possibly you need to keep text data within the regular way and also the values in the checkboxes inside a separate table.
Possibly just a little off subject, but to operate round the checkbox functionality, give a hidden input with similar title prior to the checkbox and cost - zero (or perhaps a value which means 'not set'):
<input type="hidden" name="blah" value="0"> <input type="checkbox" name="blah" value="1">
for the reason that way, when the checkbox is not checked, you will still obtain a worth of
0 inside your publish - but when it's checked, you're going to get
1, since the last area of the identical title is