如何比较用户的答案和正确答案? [英] How to compare user answer with correct answer?
问题描述
我有一个名为Quiz的数据库,我想检查用户从单选按钮列表中选择的答案是否正确答案。
正确答案存储在数据库中,当用户点击单选按钮时,我将用户答案存储在数据库中。
如何进行比较?
表格包含4列( QuestionID
, description
, correctAnswer
, userAnswer
)。
总之,当我点击按钮时如何比较数据库中的这两列?
如果<$ c的值$ c> correctAnswer 与 userAnswer
相同。
谢谢
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
推荐答案
这可能不是你想要的方式。
想一想 - 会不会有一个以上用户?如果是这样,那么你想用他的答案记录每个用户,而不是在同一个表中记录正确的答案。
我只是在猜你是什么做,但鉴于你似乎是多项选择,我会有几个表:
问题:
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
ID可以是INT或UniqueID取决于您的喜好。
这样,您可以从数据库中获取单选按钮旁边的文本,并将用户结果记录在不同的表中,交叉引用它到问题n和回答的用户。
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.
这篇关于如何比较用户的答案和正确答案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!