我有3张连接的表
表1命名为"问题"
Q_ID | C_ID | Question | Answer
1 | 1 |Question_1 | Answer_1
表2命名为"回答"
ID | Q_ID | C_ID | Answer_A | Answer_B | Answer_C
1 | 1 | 1 | Dummy Answer 1 | Dummy Answer 2 | Dummy Answer 3
和表3命名为"类别"它是连接所有表的那个,并且我的代码在获取要在我的html中显示的数据
select question.answer, answer.answer_a, answer.answer_b, answer.answer_c from question INNER JOIN answer ON question.q_id = answer.q_id where category.c_id=1
我想得到的是像
那样改变答案a. Dummy Answers 1 b. Dummy Answer 3 c. Answer_1 d. Dummy Answers 2
答案 0 :(得分:0)
您可以使用ORDER BY RAND()随机化结果
SELECT question.answer, answer.answer_a, answer.answer_b, answer.answer_c from question
INNER JOIN answer ON question.q_id = answer.c_id
INNER JOIN answer on category.c_id = answer.q_id
WHERE category.c_id=1 ORDER BY RAND()
检查此link以获取更多说明
答案 1 :(得分:0)
我认为如果你使用this ERD,那么在知道哪一个是正确的同时选择和改组问题会更容易。
因此,只有一个“问题”表包含问题,而“答案”表包含问题的所有可能答案,您可以标记正确的答案。
在示例中,如果要以随机顺序选择答案,则可以执行以下操作:SELECT * FROM answers WHERE question_id = ? ORDER BY RAND()
。用问题ID替换问号,然后设置。