SiobhanElara
asked on
How do you use multiple variables in loops?
I have a quiz with the information (ID [the auto-incremented primary], question, a [answer a], b [answer b], c [answer c], d [answer d], and correct [the correct answer; a, b, c, or d]) in a database. To output the quiz I used a simple loop over a query that gets all the questions:
<cfset i=1>
<table>
<cfloop query="qGetQuestions">
<tr>
<td>#i#.</td>
<td>#question#<br />
<table>
<tr>
<td><input name="#ID#" type="radio" value="a"></td>
<td>#a# </td>
</tr>
<tr>
<td><input name="#ID#" type="radio" value="b"></td>
<td>#b# </td>
</tr>
<tr>
<td><input name="#ID#" type="radio" value="c"></td>
<td>#c#</td>
</tr>
<tr>
<td><input name="#ID#" type="radio" value="d"></td>
<td>#d#</td>
</tr>
</table></td>
</tr>
<cfset i = i + 1>
</cfloop>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
Not a problem. The problem comes when trying to score. If I loop through the query again, I need to check and see if #qGetQuestions.correct# is equal to #FORM.#ID##, which is obviously not a valid variable. How do I go about this, or have I been going about the test setup incorrectly from the start?
Thanks!
<cfset i=1>
<table>
<cfloop query="qGetQuestions">
<tr>
<td>#i#.</td>
<td>#question#<br />
<table>
<tr>
<td><input name="#ID#" type="radio" value="a"></td>
<td>#a# </td>
</tr>
<tr>
<td><input name="#ID#" type="radio" value="b"></td>
<td>#b# </td>
</tr>
<tr>
<td><input name="#ID#" type="radio" value="c"></td>
<td>#c#</td>
</tr>
<tr>
<td><input name="#ID#" type="radio" value="d"></td>
<td>#d#</td>
</tr>
</table></td>
</tr>
<cfset i = i + 1>
</cfloop>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
Not a problem. The problem comes when trying to score. If I loop through the query again, I need to check and see if #qGetQuestions.correct# is equal to #FORM.#ID##, which is obviously not a valid variable. How do I go about this, or have I been going about the test setup incorrectly from the start?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open a new question please for that formating.
ASKER
You got #numberCorrect# of #totalQuestions# questions correct!
1. #question#
The correct answer is #textOfCorrectAnswer#. You answered #textOfExamAnswer#.
Etc.