Looping Over a Query
Hello. I have this page. My problem is that when the table is generated, the scores are only filled in for the first test column. I've tried rearranging the loops and outputs, but I can't seem to get it to output correctly. Any ideas? Thanks.
<cfquery name="testnames" datasource="AITE_Test_System"> SELECT Test_Name FROM dbo.[Tests] WHERE Class_ID = 'de8e2958-dffe-4db0-8b01-2447294db854' ORDER BY Test_ID </cfquery> <cfquery name="tests" datasource="AITE_Test_System"> SELECT Test_ID FROM dbo.[de8e2958-dffe-4db0-8b01-2447294db854] ORDER BY Test_ID </cfquery> <cfquery name="students" datasource="AITE_Test_System"> SELECT Fname, Lname, AD_Username FROM dbo.[Students] WHERE A1_Class = 'de8e2958-dffe-4db0-8b01-2447294db854' ORDER BY Lname, Fname </cfquery> <table width="100%" border="0" align="center"> <tr align="center"> <th scope="col">Last Name</th> <th scope="col">First Name</th> <cfoutput query="testnames"> <th scope="col">#Test_Name#</th> </cfoutput> </tr> <cfoutput query="students"> <tr align="center"> <td>#Lname#</td> <td>#Fname#</td> <cfloop query="tests"> <cfquery name="scores" datasource="AITE_Test_System"> SELECT Score FROM dbo.[de8e2958-dffe-4db0-8b01-2447294db854] WHERE Student_AD_Username = '#students.AD_Username#' AND Test_ID = '#tests.Test_ID#' ORDER BY Test_ID, Student_Lname, Student_Fname </cfquery> </cfloop> <cfloop query="scores"> <td>#scores.Score#%</td> </cfloop> </cfoutput></tr> </table>
