wee493 Posted July 1, 2016 Share Posted July 1, 2016 I'm creating a quiz type application where there are hundreds of quetsions in a database and they are all tagged with chapter and sub chapters in my review material where they've come from. I have a page where users can select which chapters/sub chapters to answer questions from. I need help on the best way to save which questions the user will be doing and incrementing to the next question through them taking the quiz. With a normal quiz it's easy to increment id + 1 to the next question, but in this case I assume I need to store an array of what questions they're doing in a session? Or should I store it in the database with a pointer to a quiz session id? What would you recommend? Any ideas are appreciated, thank you! Quote Link to comment https://forums.phpfreaks.com/topic/301420-give-users-random-subsets-of-questions-from-different-chapters/ Share on other sites More sharing options...
Jacques1 Posted July 1, 2016 Share Posted July 1, 2016 The problem with an array is that it's rather cumbersome to turn that back into the corresponding rows. And the results are lost forever once the session has been garbage-collected, which means you don't really know what's happening on your site (no usage statistics, no overview, nothing). Storing the questions in the database will give you a lot more flexibility. I'd create one table for the quiz instances and one table for the randomly ordered questions of each quiz (together with their status). The session only needs to contain the quiz ID. Quote Link to comment https://forums.phpfreaks.com/topic/301420-give-users-random-subsets-of-questions-from-different-chapters/#findComment-1534188 Share on other sites More sharing options...
requinix Posted July 2, 2016 Share Posted July 2, 2016 +1 to storing. Think of it not about the user answering the general "Linear Algebra" quiz but about them generating their own dedicated "Linear Algebra #1234" quiz and then answering it. Quote Link to comment https://forums.phpfreaks.com/topic/301420-give-users-random-subsets-of-questions-from-different-chapters/#findComment-1534189 Share on other sites More sharing options...
ginerjm Posted July 2, 2016 Share Posted July 2, 2016 Feeling magnanimous this morning let me throw in my $.02 and give you a little outline of what the previous responders are suggesting. 1 - define all of your questions (as you said) by subject/chapter/subchapter/unique Q#/ etc. 2 - design a table to hole #1 - one record per question with all of its identifying criteria. During this design phase, be sure you have all of the possible attributes you may need for each question down the road. Maybe a date added to keep track of older questions (outdate perhaps?) or other such things. 3 - define a table to define your users. A name, an id, contact info and any other attributes you may need for your testees. You will have a record for each person who takes your quizzes. 4 - define a quiz table that will contain a user id from #3, a quiz datetime, the key info from #1 for each question that is part of this quiz and a result field to track the user's score on each question. Here you will have a record for each question for each quiz for each user. Make sense? When all is done you will be able to pick a user, show how many quizzes he/she has taken, when it was done and what their score was. You can also track what questions have been used the most or have been used for this user. To create a specific quiz you do a query of your questions to select what you want to test on. If this selection needs to be trimmed to eliminate questions already answered in other quizzes, you will have to either add that to your query or loop thru the query results and create that array you were thinking of with the question key info and using some logic to drop the repeat questions. from that array. If you also want to shorten the list by using some random number selector you can do this against that array as step 2 of this process. Once you have modified your list of questions into table #4. Now you can output this as a complete quiz and then update it with the answers/scores when the user finishes. This is an outline, taking into consideration what I kinda gleaned from your initial post. Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/301420-give-users-random-subsets-of-questions-from-different-chapters/#findComment-1534191 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.