Jump to content

Capturing multiple selections


Omzy

Recommended Posts

This isn't strictly PHP related - more to do with object orientated design / database principles.

 

Basically I'm creating a form that has a set of checkboxes (about 75 in total), the user can have multiple selections here. How should the database be designed to store multiple selections? Do I have one field that stores the selections in a comma-separated array, or do I create separate fields in the database for each checkbox?

 

What is the recommended way of doing this for OO PHP?

Link to comment
Share on other sites

Your storage method / design isn't related to OO PHP at all. Personally I'd refrain from using a comma-separated list. Not only does it make removing/updating certain values more complex than necessary, you'll also loose a lot of the functionality / search-ability of your database platform. Instead go with one row per-selection; may seem like it would be more resource heavy but in actual fact when it came to removing/updating that would be more efficient than using the comma-separated list.

Link to comment
Share on other sites

you should have two tables for example using a survey

 

table: survey

 

surveyid

surveyusername

 

table: surveyanswer

 

surveyanswerid

surveyid

surveyanswervalue

 

and then in your case the survey answer table would have 75 entries for one survey but they would all have the same surveyid so that they could be related back to the survey that was taken. that is pretty basic but should give you the idea.

 

Link to comment
Share on other sites

well, if you incorporated a question table and then added a questionid field to the surveyanswer table then you would be able to have more than one multiple selection question as they would all have different combinations of id's.

 

for example:

 

survey 1

question 1

answer 1

answer 2

answer 3

answer 4

 

would be different to

 

survey 1

question 2

answer 1

answer 2

answer 3

answer 4

 

as you see putting the id's side by side you would get something along the lines of:

 

111

112

113

114

 

for the first set and

 

121

122

123

124

 

for the second set.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.