Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Count structure values

Participant ,
Oct 29, 2008 Oct 29, 2008
Right now i count my structure (named "answer") values by:

<cfset answers_sum = answer.response.sum1 + answer.response.sum2 + answer.response.sum3 + answer.response.sum4 + answer.response.sum5 + answer.response.sum6 />

Of course that is not the way to do so as i want it in a loop count to always (despite amount of answer fields in the db) be able to correctly calculate the total.

So it must be in a loop like <cfloop index="i" from="1" to="#application.dbquestions#"> but how do i calculate the total?

Thanks
534
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 29, 2008 Oct 29, 2008
Array notation to the rescue.

<cfset answers_sum = answers_sum + answer["resonse"]["sum" & i]>
Translate
LEGEND ,
Oct 29, 2008 Oct 29, 2008
Array notation to the rescue.

<cfset answers_sum = answers_sum + answer["resonse"]["sum" & i]>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 29, 2008 Oct 29, 2008
LATEST
Thanks! 🙂 (also gave answers_sum a default value of 0 to enable it's usage, might sound logical but just in case someone else need that info)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources