Discussion Forums  >  Uncategorized

Replies: 9    Views: 211

digira
Lost but trying
Profile
Posts: 18
Reg: Nov 10, 2011
location unknow...
180
12/26/11 09:50 AM (14 years ago)

Multiple Choice Quiz 1.5 - randomize

Hi, I've created a multiple choice quiz pulling the questions from a defined dataURL on my own host. When viewing the quiz, the same question always appears as the first question and the answer in the exact same location. I am drawing from 300+ questions. I've specified in the Quiz Behavior to Randomize Question Order. Yet, the same question appear first!? Any help on how to shuffle the questions and answers would be appreciated.
 
Parker @ buzztouch
buzztouch Evangelist
Profile
Posts: 1395
Reg: May 09, 2011
Pacific Grove, ...
24,500
like
12/26/11 04:24 PM (14 years ago)
Hi digira, The 'Randomize Question Order' option only applies to questions within the app, entered through the control panel. In your case you will need to write a script (.php?) accessed through your Data URL that will query your database and randomize the questions and answers returned.
 
digira
Lost but trying
Profile
Posts: 18
Reg: Nov 10, 2011
location unknow...
180
like
12/26/11 05:12 PM (14 years ago)
Thanks. Has anyone done this before? Maybe some code lying around!
 
MQCMobile
Lost but trying
Profile
Posts: 85
Reg: Feb 13, 2011
Oklahoma
5,950
like
12/29/11 02:06 PM (14 years ago)
How hard would it be to randomize the answers?
 
Parker @ buzztouch
buzztouch Evangelist
Profile
Posts: 1395
Reg: May 09, 2011
Pacific Grove, ...
24,500
like
12/29/11 05:08 PM (14 years ago)
@ maune12, It all depends on how you have your questions and answers stored. Are they 'hard coded' in a JSON .txt file or are they values in a database? Either way it would be a matter of coding logic to randomize the returned order of the answers and or questions. The difficulty of which depends on your coding ability.
 
MQCMobile
Lost but trying
Profile
Posts: 85
Reg: Feb 13, 2011
Oklahoma
5,950
like
01/03/12 10:16 AM (14 years ago)
Thanks Parker. I currently have a php script written for the quiz, but it doesn't work with the app (I don't know why). I've gone to the validation website and it comes back as a valid JSON format, but when I try to have the app use it all I get back is the problem parsing error make sure it is well formed. If I take the script that I get when I go to the site on my server where it's located and save it as a text file then direct the app to go to the text file, then it works. Any thoughts?
 
Parker @ buzztouch
buzztouch Evangelist
Profile
Posts: 1395
Reg: May 09, 2011
Pacific Grove, ...
24,500
like
01/04/12 11:50 PM (14 years ago)
It kinda sounds like you might be outputting your result in HTML which then displays in a browser as valid JSON? Can you post a link to the script?
 
MQCMobile
Lost but trying
Profile
Posts: 85
Reg: Feb 13, 2011
Oklahoma
5,950
like
01/05/12 12:54 PM (14 years ago)
Thanks for the reply. Here is the URL http://www.myquizcoach.com/extras/quiz_JSON_template.php I do have the html stripped from the JSON output, and when I copy and paste into the JSON validator (@ http://jsonlint.com/) it comes back as valid JSON. Would it be beneficial for me to email you the script? Thanks
 
MQCMobile
Lost but trying
Profile
Posts: 85
Reg: Feb 13, 2011
Oklahoma
5,950
like
01/05/12 02:46 PM (14 years ago)
Thanks again Parker! I tried out a different way to use the JSON validator program at (http://jsonlint.com) by placing the URL the script was on and placed a ?reformat=compress after the URL. The validator returned a place on the string that had a carriage return placed in it. It was a database problem not the php I wrote. Thanks again for the help. Hopefully this will help out some others too. I don't know why going to the URL and copying and pasting the output into the validator didn't notice that. Thanks again.
 
MQCMobile
Lost but trying
Profile
Posts: 85
Reg: Feb 13, 2011
Oklahoma
5,950
like
01/11/12 10:58 PM (14 years ago)
@ Parker. As per our conversation above I can't figure out how to randomize the output for the answers. Here is a copy to my script I'm running (I'm a noob, so this might not be pretty to a pro, but it works with the quiz). All suggestions and criticisms are welcome. Thanks. <?php //Sample Database Connection Syntax for PHP and MySQL. //Connect To Database $hostname=; $username=; $password=; $dbname=; $question_table=wp_mtouchquiz_question; $answer_table=wp_mtouchquiz_answer; $yourfield = question; $question = question; $answer = answer; $connection = mysql_connect($hostname, $username, $password); $lastQuestionID = -1; $str = ; mysql_select_db($dbname, $connection); # Check If Record Exists $query = SELECT * FROM $question_table q, $answer_table a WHERE q.ID = a.QUESTION_ID AND q.quiz_id = 1 ORDER BY question_id ASC, correct DESC; $result = mysql_query($query); if($result) { $str .= {\childItems\:[; while($row = mysql_fetch_array($result)) { if($lastQuestionID != $row[question_id]) { if($lastQuestionID != -1) { // finish off the last two rows $str .= \imageURLSmallDevice\:\\,; $str .= \imageURLLargeDevice\:\\},; } $lastQuestionID = $row[question_id]; $str .= {\itemId\:\question . $row[question_id] . \,; $str .= \itemType\:\BT_questionItem\,; $str .= \questionText\:\ . $row[question] . \,; } // correct if($row[correct] == 1) { $str .= \correctAnswerText\:\ . $row[answer] . \,; } // incorrect if ($row[sort_order] ==2) { $str .= \incorrectText1\:\ . $row[answer] . \,; } // incorrect if ($row[sort_order] ==3) { $str .= \incorrectText2\:\ . $row[answer] . \,; } // incorrect if ($row[sort_order] ==4) { $str .= \incorrectText3\:\ . $row[answer] . \,; } {$str = strip_tags($str); } } $str .= \imageURLSmallDevice\:\\,; $str .= \imageURLLargeDevice\:\\},; // remove last comma $str = substr($str,'',-1); $str .= ] }; echo $str; } ?>
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.