I am building a small online app (PHP/MySQL) where users can sign-up to become members, and inside the members area they have a list of quizzes they can take.
When displaying the list of quizzes for a given user (i.e. his browser just requested the page with the list), I need to know, for each quiz, whether or not the user already took it in the past. Cause if he did I’ll display a checkmark aside to it. This is to help users keep track of their usage of the site.
My problem: So basically I need to store a list of “taken quizzes” for each user. But I am not sure about the best way of doing it.
My solution so far: Each quiz has an ID, so I am planning to store the list of “taken quizzes” for each user as a string (with values separated by commas) on my database. Then when I need to use it I read the string from the database and transform it into an array (and vice-versa for storing it back).
UPDATE: Apparently there are 2 viable options: 1) is to use the method I described above storing the array as a string, 2) is to create another MySQL table to store the quiz-id/user-id pairs. At this point I am wondering which solution is faster, should the site become popular. With the first option I will have the extra work of converting the string to an array and back, but after that I’ll be searching on a small array (i.e., containing only the quizzes taken by the single user). With the MySQL solution I wouldn’t need to convert strings back and forth, but I would need to search on a much larger dataset (i.e., all the quizzes taken by all the users). Any guess on which method is faster for a large number of users (e.g., 1000)?
If you use some thing like MySQL then try a similiar table structure:
TABLE: users
user_id | user_nameTABLE: quiz
quiz_id | quiz_nameTABLE: quiz_taken
taken_id | user_id (FK) | quiz_id (FK) | timestampAdd an entry into the quiz_taken table for each participation in the quiz. Also, you can always add more coloumns to store more details.