2011-03-17 47 views
0

我有一個問題,我試圖用基於quizzin(WordPress插件)的mtouch測驗安裝測驗,我需要從數據庫中選擇一個正確答案和3個隨機答案。
ID - question_id ------答案-----提示-----正確------ sort_order
1 -------- 1 -------- --------- test1 --------------------- 1 ---------------- 1
2 -------- 1 --------------- test 1 --------------------- 0 ---------------- 2
3 -------- 1 --------------- test2 ----- ---------------- 0 ---------------- 3
4 -------- 1 ---- ----------- TEST3 --------------------- 0 ---------------- 4
5 -------- 2 --------------- test5 --------------------- 1 ---------------- 1從sql mtouch測驗挑選隨機行

以上是sql結構的例子,我想要做的是擺脫不正確的答案並使用正確的答案,從其他的問題,使他們錯誤的答案,即問題1

http://wordpress.org/extend/plugins/mtouch-quiz/

我只需要現在如何編輯show_quiz.php文件來做到這一點。

如果($ random_answers == 1){$ 丹斯= $ wpdb-> get_results(「選擇ID,應答,正確的,暗示FROM {$ wpdb->前綴} mtouchquiz_answer WHERE question_id = {$ ques-> ID } ORDER BY RAND()「); //這會將問題答案順序隨機化 }其他{dans = $ wpdb-> get_results(「SELECT ID,answer,correct,hint FROM {$ wpdb-> prefix} mtouchquiz_answer WHERE question_id = {$ ques-> ID } ORDER BY sort_order「); } 任何人都可以幫忙。感謝

+0

看看這可能會給你一些啓發http://stackoverflow.com/questions/31495446/how-to-get-random-records-from-each-category-in-mysql/31496011? noredirect = 1#comment50972156_31496011 – 2015-07-20 21:51:10

回答

0

這會給你3個正確的答案來自其他問題

SELECT * FROM {$ wpdb->前綴} mtouchquiz_answer WHERE question_id!= {$ ques-> ID},正確= 1 ORDER BY RAND()限制0,3