5 Replies Latest reply on Aug 25, 2007 9:43 AM by CFMXPrGrmR

    Looping and setting cfset values (from a query)

    CFMXPrGrmR Level 2
      Stuck on how to get this to work.

      How would I go about looping and setting these values instead of doing them individually?

      The query this <cfset> references works fine and will work but repeats...

      <cfset ans1 = (qryGetPcts1.q1Ct / qryGetCounts.qID2) * 100>
      <cfset ans2 = (qryGetPcts2.q2Ct / qryGetCounts.qID2) * 100>
      <cfset ans3 = (qryGetPcts3.q3Ct / qryGetCounts.qID2) * 100>
      <cfset ans4 = (qryGetPcts4.q4Ct / qryGetCounts.qID2) * 100>
      <cfset ans5 = (qryGetPcts5.q5Ct / qryGetCounts.qID2) * 100>

      So I'd like to loop and set them all instead...

      <cfloop index="i" from="1" to="27">
      <cfset ans#i# = (qryGetPcts#i#.q#i#Ct / qryGetCounts.qID2) * 100>

      But it's responding with this...

      Invalid CFML construct found on line 196 at column 19.
      ColdFusion was looking at the following text:

      I'm sure I'm missing something simple b/c this must be possible? Can I use a cfset in a loop?

      Help is appreciated