Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6347941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:19:22+00:00 2026-05-24T21:19:22+00:00

I’m trying to set up a database for multiple choice test that will be

  • 0

I’m trying to set up a database for multiple choice test that will be taken by multiple users. And I am having a difficulty setting up the database and the application logic.

This is how I see the application should behave:

  1. A user starts the test and answers as many questions as they want (questions should be picked randomly).
  2. The questions that the users see should not be the ones that were answered correctly before by the same user.

Here is how I set up the database:

database

So my questions are:

  1. Is my database set up correctly so that it satisfies the above requirements?
  2. What is the best way to show questions to the users (keeping in mind the above requirements)? Should I get all the questions that were answered correctly in an array and then all the existing questions in another array, and the exclude the first array from the second, and shuffle the resulting array? I don’t think this way is efficient at all.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:19:22+00:00Added an answer on May 24, 2026 at 9:19 pm

    Your schema will almost work, as long as you only have one test, and as long as you don’t want to record the users’ answers, just whether they got it right or not. One issue that I see is that I can’t see where the right answer is recorded. How will the system know if the user picks the right answer?

    Also, some people might be a little concerned about your questions table having unnormalized answers. Another way to do this would be to have an answer table like this:

    answers
    ( id,
      question_id,
      sequence,
      answer_value
    )
    

    The advantage of this is that you can have any number of answers per question and you don’t need to either make up extra wrong answers or change your system should a question with more answers be required.

    Note too that if you use this approach then your question table should also have an indication of which answer is the correct one, such as “correct_answer_id” – This type of relationship is tricky to manage if you have referential integrity implemented in the database, due to the chicken and egg problem, so you’re going to need some application code to ensure that every question has an answer and that it’s answer is not for a different question!

    You didn’t mention this in your post, but stats.is_answered_correctly allows you avoid showing users questions that they got wrong, as well as questions that they got right. If you only want to know which questions the user got right and are prepared to show them the same question many times until they get it right, then you don’t really need the “is_answered_correctly” attribute. Instead the mere existence of the intersection record tells you that the question was answered correctly.

    In terms of picking questions, there are two ways you could go about it. If you have many more questions than any single user will ever answer, then you could just pick a question randomly, check to see if they happen to have answered it, and if so, go back and get a different one. If the question set is much larger than the answer set there will be a very low probability of collisions and you should be fine.

    If your question set is not much bigger than your answer set, you could instead make a work list of unaswered questions. This would involve an intersection table containing a pairing of the user with every question. You would build this once when the user first signs up. When you ask a question you pick it randomly from the questions related to that user in this work list table. When the user gets a question right, you delete the intersection record so that question won’t be asked again. This is pretty efficient, but it will require a database call to count the number of unanswered questions for your particular user prior to randomly selecting one from the work list table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.