I am creating a multiple choice quiz using a multidimensional associative array then displaying it using a for each loop. SO PROUD!!! However, I can not figure out how to keep the choice selected for each question while going through the quiz.(all questions are displayed on the same page) Does this have to do with form validation or am I supposed to be declaring something in my form? I have tried so many things HELP :)
-
2**If I understand you correctly** ---- Please use a different name for each of your radio button set – Ken Lee Nov 07 '21 at 01:40
-
Thanks for your answer :) I do have a name for each of my questions: $questions = array( 0 => array('question' => 'Which term describes the gear a fisherman uses?', 'name' => 'q1', 'choices' => array( 'luggage', 'tackle',//correct 'supply', 'paraphernalia'), 'answer' => 'tackle'), – uniquelyDistinguished Nov 07 '21 at 15:55
1 Answers
Your question is not very clear! add sample of your code. In general, if all questions are in the same page and you don't need to navigate to another page while doing the quiz, you need to assign unique name for each question in the form, when user choosing any choice, the value will be saved in the input.
Second solution is: if you need to navigate between many pages while doing the quiz, for example (if all 5 questions are in separate page) in this case you need to keep questions data in persistent storage even for temporary time, the persistent storage is like: Database, text files, json files , or temporary in session ($_SESSION).
Choosing one of them depends on the needed requirements and the developer's preferences.
See this question and answers, I think it will give you some info about your issue: Persistent data in a web app
If these ways don't meet your requirements or don't help to solve the issue, you can notify us and explain your question more clearly.

- 335
- 1
- 2
- 14