Tantalum Posted May 5, 2009 Share Posted May 5, 2009 I have a set of questions that are located in a XML file. Using php, I need to pull the questions from the XML file and shuffle the order of the questions each time they are displayed to the user. What is the best way to implement this? Please be specific in your instructions and syntax because I am fairly new to php programming? Thank you! John Link to comment https://forums.phpfreaks.com/topic/156992-how-to-shuffle-questions-using-php/ Share on other sites More sharing options...
chipmunken Posted May 5, 2009 Share Posted May 5, 2009 I suggest to use the php xml DOM functions, start playing with the examples provided by the php manual Link to comment https://forums.phpfreaks.com/topic/156992-how-to-shuffle-questions-using-php/#findComment-827016 Share on other sites More sharing options...
Ken2k7 Posted May 5, 2009 Share Posted May 5, 2009 Best way is to use a DB and not XML. I'm not sure about randomizing values in a XML file. I never done that before. Link to comment https://forums.phpfreaks.com/topic/156992-how-to-shuffle-questions-using-php/#findComment-827038 Share on other sites More sharing options...
allworknoplay Posted May 5, 2009 Share Posted May 5, 2009 You could just take the XML data, put it into an array, and then use the shuffle() function to randomize the output... Link to comment https://forums.phpfreaks.com/topic/156992-how-to-shuffle-questions-using-php/#findComment-827057 Share on other sites More sharing options...
Ken2k7 Posted May 5, 2009 Share Posted May 5, 2009 You could just take the XML data, put it into an array, and then use the shuffle() function to randomize the output... I think that would only work if the XML only had the questions and nothing else. Not sure what the structure of the XML file is. Link to comment https://forums.phpfreaks.com/topic/156992-how-to-shuffle-questions-using-php/#findComment-827061 Share on other sites More sharing options...
Tantalum Posted May 6, 2009 Author Share Posted May 6, 2009 You could just take the XML data, put it into an array, and then use the shuffle() function to randomize the output... I think that would only work if the XML only had the questions and nothing else. Not sure what the structure of the XML file is. Here is the structure of my XML file: <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/css" href="States.css"?> <MULTIPLE_CHOICE> <STATES> <QUESTION>41. Which state was first admitted to the Union?</QUESTION> <CHOICE_A>a. Pennsylvania</CHOICE_A> <CHOICE_B>b. New Jersey</CHOICE_B> <CHOICE_C>c. Delaware</CHOICE_C><!--C is the corrrect Answer--> <CHOICE_D>d. Georgia</CHOICE_D> </STATES> <STATES> <QUESTION>42. What was the 36th state admitted to the Union?</QUESTION> <CHOICE_A>a. West Virginia</CHOICE_A> <CHOICE_B>b. Nebraska</CHOICE_B> <CHOICE_C>c. Nevada</CHOICE_C><!--C is the corrrect answer--> <CHOICE_D>d. North Dakota</CHOICE_D> </STATES> <STATES> <QUESTION>43. What state has the nickname "Centennial State"?.</QUESTION> <CHOICE_A>a. Texas</CHOICE_A> <CHOICE_B>b. New Mexico</CHOICE_B> <CHOICE_C>c. Colorado</CHOICE_C><!--C is the corrrect answer--> <CHOICE_D>d. Arizona</CHOICE_D> </STATES> <STATES> <QUESTION>44. Pierre is the capital city of what state.</QUESTION> <CHOICE_A>a. Nebraska</CHOICE_A> <CHOICE_B>b. New Mexico</CHOICE_B> <CHOICE_C>c. North Dakota</CHOICE_C> <CHOICE_D>d. South Dakota</CHOICE_D><!--D is the corrrect Answer--> </STATES> <STATES> <QUESTION>45. What state has the highest point in elevation?.</QUESTION> <CHOICE_A>a. West Virgina</CHOICE_A> <CHOICE_B>b. Missouri</CHOICE_B> <CHOICE_C>c. Alaska</CHOICE_C><!--Corrrect Answer--> <CHOICE_D>d. Washington</CHOICE_D> </STATES> <STATES> <QUESTION>46. What state has the nickname "Bluegrass State"? </QUESTION> <CHOICE_A>a. Tennessee </CHOICE_A> <CHOICE_B>b. Kentucky</CHOICE_B><!--Corrrect Answer--> <CHOICE_C>c. Virgina</CHOICE_C> <CHOICE_D>d. Ohio</CHOICE_D> </STATES> <STATES> <QUESTION>47. Which state has the motto: Friendship .</QUESTION> <CHOICE_A>a. Texas</CHOICE_A><!--Corrrect Answer--> <CHOICE_B>b. Oklahoma</CHOICE_B> <CHOICE_C>c. Arkansas</CHOICE_C> <CHOICE_D>d. Michigan</CHOICE_D> </STATES> <STATES> <QUESTION>48. The Ohio River begins in what state?</QUESTION> <CHOICE_A>a. Ohio</CHOICE_A> <CHOICE_B>b. Indiana</CHOICE_B> <CHOICE_C>c. Pennsylvania</CHOICE_C><!--Corrrect Answer--> <CHOICE_D>d. Michigan</CHOICE_D> </STATES> <STATES> <QUESTION>49. Which state was admitted last to the Union?</QUESTION> <CHOICE_A>a. Alaska</CHOICE_A> <CHOICE_B>b. Hawaii</CHOICE_B><!--Corrrect Answer--> <CHOICE_C>c. California</CHOICE_C> <CHOICE_D>d. Montana</CHOICE_D> </STATES> <STATES> <QUESTION>50. What state has the longest coastline?</QUESTION> <CHOICE_A>a. Georgia</CHOICE_A> <CHOICE_B>b. California</CHOICE_B> <CHOICE_C>c. Alaska</CHOICE_C><!--Corrrect Answer--> <CHOICE_D>d. Alabama</CHOICE_D> </STATES> <body> </body> </MULTIPLE_CHOICE> Thank you for your help! John Link to comment https://forums.phpfreaks.com/topic/156992-how-to-shuffle-questions-using-php/#findComment-828025 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.