Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a database named Quiz and I would like to check if the user selected answer from the radio button list is the the correct answer.

The correct answers are stored in the database and I am storing the user answer in database as the users clicks the radio button.

How can I make that the comparison?

The table Questions contains 4 columns (QuestionID, description, correctAnswer, userAnswer).

So in conclusion, how can I compare those 2 columns from database when I click the button?
If the values of correctAnswer are the same with userAnswer.

Thanks
Posted
Updated 6-Apr-13 5:03am
v3
Comments
vinodkumarnie 6-Apr-13 13:49pm    
Don't expect the answer from others.. Please do think yourself..

1 solution

That's probably not the way you want to do it.
Think about it for a moment - will there ever be more than one user? If so, then you want to record each user with his answer, rather than record the correct answer in the same table.

I'm just guessing what you are doing, but given that you seem to be multiple choice, I would have a couple of tables:
Questions:
QuestionID              INT or UID
QuestionDescription     VARCHAR
Answer1                 VARCHAR
Answer2                 VARCHAR
Answer3                 VARCHAR
Answer4                 VARCHAR
CorrectAnswer           INT
Answers
AnswerID                INT or UID
QuestionID              INT or UID
UserID                  INT or UID
UserAnswer              INT
The IDs Would be either INT or UniqueID depending on what you prefer.
This way, you get the text that goes beside the radio button from the DB, and record the user results in a different table, cross referencing it to the question and the user that answered.
 
Share this answer
 
Comments
pantelis89 6-Apr-13 11:37am    
Well, i have 2 tables, one is Questions with the columns i said above and the other is Choices with 4 columns there too (ChoiceID, QuestionID, ChoiceText, ChoiceValue) choices are binded to radiobuttonlist and connected with detailsview with QuestionID, so every questions changes at detailsview, radiobuttonlist gets the choices. Questions are binded to Detailsview.
Every time user is loading the quiz , userAnswer are reseting to default (1st choice).
I just want to have the opportunity to check every question with a button if it's correct or not.
Give me some idea if it's possible on that. I just want to compare those 2 values. One from correctAnswer and the other from userAnswer.
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900