I'm working on a training course application, and this is a first for me so I'm hitting a bit of a snag. I have a form, the training assessment, which when submitted, sends an array of id's and selected answers to the php page for processing. My thoughts are to run a mysql query selecting a count of correct answers, then another to select a count of distinct questions, then divide the two to calculate the score. That part is simple enough, but my mind is melting trying to figure out the query for selecting the count of correct answers.
Here is the code for my form...
<form name="assessment" method="post" action="scripts/scoreAssessment.php">
<ul class="assessment">
<li class='question'>This is a question?
<ul style='list-style:none;'>
<li><input name='trainingCourseAnswer[]' type='radio' value='A1'/>This is a multiple choice answer.</li>
<li><input name='trainingCourseAnswer[]' type='radio' value='B1'/>This is a multiple choice answer.</li>
<li><input name='trainingCourseAnswer[]' type='radio' value='C1'/>This is a multiple choice answer.</li>
<li><input name='trainingCourseAnswer[]' type='radio' value='D1'/>This is a multiple choice answer.</li>
</ul>
</li>
<li class='question'>This is a question?
<ul style='list-style:none;'>
<li><input name='trainingCourseAnswer[]' type='radio' value='A2'/>This is a multiple choice answer.</li>
<li><input name='trainingCourseAnswer[]' type='radio' value='B2'/>This is a multiple choice answer.</li>
<li><input name='trainingCourseAnswer[]' type='radio' value='C2'/>This is a multiple choice answer.</li>
<li><input name='trainingCourseAnswer[]' type='radio' value='D2'/>This is a multiple choice answer.</li>
</ul>
</li>
<!--continue pattern for total number of questions-->
</ul>
<input name='submitAssessment' type='submit' value='Finish Test'/>
</form>
In scoreAssessment.php, I can split the value for the selected radio input answers using the PHP substr function to get two variables, $selectedAnswer and $answerID. The query that I need to run to select all correct answers would be as follows...
$selectedAnswer=substr($_POST['trainingCourseAnswer'], 0, 1);
$answerID=substr($_POST['trainingCourseAnswer'], 1);
$query="SELECT COUNT(correctAnswer) WHERE answerID='$answerID' AND correctAnswer='$selectedAnswer'"
The issue I have with that is that both $answerID and $selectedAnswer are arrays with multiple values...
Can anyone offer some guidance? I would greatly appreciate it!