Link to home
Start Free TrialLog in
Avatar of SiobhanElara
SiobhanElaraFlag for United States of America

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!
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SiobhanElara

ASKER

Thanks for your response! While it does appear that the above code would tell you how many questions were correct, it doesn't seem to tell them *which* ones they got right and what the correct answer would be. (I should have specified that was what I was going for but was hoping to be able to figure that part out if the double variable thing got explained.) What I would like it to do, in the end, is to say (using explanatory variable names for clarity):

You got #numberCorrect# of #totalQuestions# questions correct!

1. #question#
    The correct answer is #textOfCorrectAnswer#. You answered #textOfExamAnswer#.

Etc.
Open a new question please for that formating.