Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy. This forum is not for asking programming related questions.
I want to make a web based test. Each test has 50 multiple choice questions with four possible answers.
I would like to use radio buttons for the possible answers and then keep count of which questions have been answered in an array.
The database will have the text of the questions and the text of the possible answers and the correct answer. When the student clicks on a button I can record his answer in the array. When he wants to be scored then I can scan the array and check against the correct answers to calculate a score.
What I was thinking about was basic page layout, then when the student chooses to go to question 2, the page would reload with new question and possible answers. That means that the array would have to be accessable from all pages and when you are responding to question 2, it would have to know to place the answer into the correct position in the array.
I want to have all the questions, etc. stored in MySQL and pull them in as needed. I was also thinking about loading all 50 questions in the beginning and loading them into variables or arrays and then just displaying them when needed.
i happen to cross this road before. the good news is that there is a ready made solution for it, so no need to reinvent the wheel i think, in this case.
there is a nice component with all the features you mention an even more
for the price of about 80 dollars, ( which i think is well worth it , considering the amount of time saved by having such a capability, especially for schools ).
It runs on Joomla CMS, Joomla itself is open source and free ( well, just in case you didn't already know).
i however did not take up this nice peice of software, as i did not have the people to manage and run the quiz site i wanted to make, i hence scrapped the project. But i did do a short study and evaluation of it so am in the know of what it can do.
Let know if you are interested, and if there is a large interest such a solution, if there is a large interest, maybe post here as well.
which brings me to another related topic, if there are people intersted in running a quiz site, please give us a holler. i still think a quiz site is a good one to make and can provide good revenue, even if for non-profit. i can build one but not maintain it.
only that i am a little confused when u says "when he wants to be scored".
how many chances does one get to be scored ?
can he check his score so far, and come back and do the rest ?
i would actually use objects, questions being one and answers being another.
you would then endup with if ($questions==$answers) which would be rather a convenient
way to check for correct answers.
To expand on php_east, I would have subclasses of each type of question ( one for multi-choice, etc.. etc.. ). I would then have a test object that held a collection of it's questions. I could ask the test object if it were valid and it would ask all of it's children, if all of it's children were valid it would return true. This is called the composite pattern. Basically you define an interface each class implements, so each class has a ->isValid() method. To expand on this further you could have a test composite other tests ( sub-tests ). Validate ranges of questions at a time ( multi-page forms ), etc..