Asheeown Posted April 29, 2009 Share Posted April 29, 2009 Okay, I'm making a simple online quiz, the PHP part gets 35 random questions and posts them on the page. All questions that are pulled from the DB are stored in an array with their ID (Example: $Questions[1] = "16", So questions 1's ID is 16) All the IDs of the correct answers are also stored in an array with their ID (Example: $Answers[1] = "20", So the answer to question 1 is the answer with the ID of 20) Now, before I go too far with the PHP and make it seem like I'm asking a question about that I need to parse the user input and display results without reloading the page. I'm not looking for someone to do it for me, I just need an idea of where to start with this. I need to pass the two arrays to javascript, and for each one I need to check it against the radio buttons the user filled out to see if they got the right answer, if not highlight theirs with red and print "Incorrect answer" next to it and print "Correct answer" next to the correct one always. The radio buttons hold the question ID in the name directive and the answer ID in the value directive. Any help would be great, I don't know where to begin. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 30, 2009 Share Posted April 30, 2009 Well you got everything down pretty much right. If you don't want page refresh but you still want communication between client's answers and the verifications on PHP, then use AJAX. Quote Link to comment Share on other sites More sharing options...
Asheeown Posted April 30, 2009 Author Share Posted April 30, 2009 I was trying to avoid Ajax this time, not that I don't think it would work in this situation it's just it seems that all I really need to do is pass the arrays and then get a nice foreach statement in there and it would work perfectly, the rest, like highlighting answers and giving results is a piece of cake. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 30, 2009 Share Posted April 30, 2009 I was trying to avoid Ajax this time, not that I don't think it would work in this situation it's just it seems that all I really need to do is pass the arrays and then get a nice foreach statement in there and it would work perfectly, the rest, like highlighting answers and giving results is a piece of cake. Oh well if you want to pass the questions and answers as 2 arrays to JavaScript, then you don't need AJAX, but then the answers would be available for anyone viewing the source. Quote Link to comment Share on other sites More sharing options...
Asheeown Posted April 30, 2009 Author Share Posted April 30, 2009 They would be passed upon submitting the form, after that I don't care what they see in the source. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.