Jump to content

How to store survey results in database


Cupidvogel

Recommended Posts

Hi, surely we all have seen in Facebook questions like Which of the following IMDB top 250 movies have you seen?, followed by a list of check-options with a button, which on clicking fetches all the members who have voted for that option (if there are two many number of such users, as for this particular question, where each option may be voted by more than a million users, the user-list is retrieved only partly and continues do so on subsequent requests from the client). Question is, how can the list of users be stored in the database? If the survey poll has an id of say, 123, the it is fair to assume that there will be a table like username_123, where there will be a column containing the option value, then one containing the option text. How to insert the list of users? One way may be by storing the user names in a string, delimited by space, and on requests, send the string to PHP, where PHP uses regular expression to split the string and extract the usernames. However the process  looks very clumsy, and very painstaking, given the fact that the column value will have to be frequently updated as more voter vote, or some of the existing voters unvote (either by withdrawing their vote altogether, or voting another item in case of radio-buttons). Any idea, anyone?

Link to comment
Share on other sites

For each movie the user votes for you insert a "vote" record containing the user id and the movie id

 

  +-----------+                              +------------+

  |  user    |                              | movie      |

  +-----------+                              +------------+

  | id        |--+                      +---| id        |

  | name      |  |                      |  | title      |

  | etc      |  |                      |  | etc        |

  +-----------|  |                      |  +------------+

                  |      +----------+    |

                  |      | vote    |    |

                  |      +----------+    |

                  |      | voteId  |    |

                  +----<  | userId  |    |

                          | movieId  | >--+

                          +----------+

 

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.