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

Dynamic <cfif queryname["answer" & i] EQ 1>

Participant ,
Oct 30, 2008 Oct 30, 2008
Is it possible to dynamically loop a <cfif queryname["answer" & i] EQ 1>? Well not for me right now :(

I use this code:

(votecheck is a query)

<cfloop index="i" from="1" to="#application.dbquestions#">
<cfif votecheck["answer" & i] EQ 1>
<cfset voteranswer = votecheck["answer" & i]>
</cfif>
</cfloop>

Earlier i learned about array notation, but that seems not to work in this situation....
515
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 30, 2008 Oct 30, 2008
do you want 'i' to represent a row in your query (your query returns N
rows of column answer), or does your query return only 1 row with N
columns answer1, answer2, ..., answerN?

if the former, correct array notation in that case is:
votecheck['answer']

if the latter, your query must be returning more than 1 row and that's
why the array notation does not work - you need to specify a query row.
this may work in this case:

<cfoutput query="votecheck">
<cfloop index="i" from="1" to="#applicati
...
Translate
LEGEND ,
Oct 30, 2008 Oct 30, 2008
do you want 'i' to represent a row in your query (your query returns N
rows of column answer), or does your query return only 1 row with N
columns answer1, answer2, ..., answerN?

if the former, correct array notation in that case is:
votecheck['answer']

if the latter, your query must be returning more than 1 row and that's
why the array notation does not work - you need to specify a query row.
this may work in this case:

<cfoutput query="votecheck">
<cfloop index="i" from="1" to="#application.dbquestions#">
<cfif votecheck["answer" & i][currentrow] EQ 1>
<cfset voteranswer = votecheck["answer" & i][currentrow]>
</cfif>
</cfloop>
</cfoutput>



Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
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 31, 2008 Oct 31, 2008
LATEST
Great! Somewhat confusing in the beginning, structures, arrays, array notation, dot notation, but as i now see in fact very simple and logical 🙂
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