Ali
Ali

Reputation: 1

select random row from sql mtouch quiz

i have a problem am trying to setup a quiz using mtouch quiz based of quizzin (WordPress plugins), i need to select one correct answer and 3 random answers from database.
ID--question_id------answer-----hint-----correct------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

the above is example of the sql structure, what i want to do is get rid of the incorrect answers and use the correct answers from other question and make them the wrong answers i.e for question 1

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

i just need to now how to edit the show_quiz.php file to do this.

if ( $random_answers == 1 ) { $dans = $wpdb->get_results("SELECT ID,answer,correct,hint FROM {$wpdb->prefix}mtouchquiz_answer WHERE question_id={$ques->ID} ORDER BY RAND()"); // This will randomize the question answer order } else { $dans = $wpdb->get_results("SELECT ID,answer,correct,hint FROM {$wpdb->prefix}mtouchquiz_answer WHERE question_id={$ques->ID} ORDER BY sort_order"); } can anyone help. thanks

Upvotes: 0

Views: 480

Answers (1)

Roy Toledo
Roy Toledo

Reputation: 643

This will give you 3 correct answers from other questions

SELECT * FROM {$wpdb->prefix}mtouchquiz_answer WHERE question_id!={$ques->ID} AND correct=1 ORDER BY RAND() limit 0,3

Upvotes: 0

Related Questions