Ama*_*man 2 variables coldfusion cfloop
你会看到我很新.我想创建以下变量:
V1 =我的查询中的单词1V2 =我的查询中的单词2我可以静态地这样做:
<cfset V1=#qryGetWords["WordName"][1]#>
<cfset V2=#qryGetWords["WordName"][2]#>
<cfset V3=#qryGetWords["WordName"][3]#>
<cfset V4=#qryGetWords["WordName"][4]#>
Run Code Online (Sandbox Code Playgroud)
但我想动态地做.我已经看到了其他答案,但我也无法让他们工作.可以通过调整语法来完成以下任何工作吗?
<cfloop query="qryGetWords" index="i">
<cfset "V#i#" = #qryGetWords["WordName"]["i"]#>
</cfloop>
Run Code Online (Sandbox Code Playgroud)
我可以在cfloop中没有索引和查询吗?
由于您使用的是查询循环,因此您已经可以访问内置索引,即query.currentRow.与cfoutput标记一样:
当您指定查询属性时,此标记将循环查询行....它还将query.currentRow变量设置为正在处理的当前行.
例:
<cfloop query="qryGetWords">
<!--- within the loop, you could also use the shortcut: qryGetWords.WordName --->
<cfset variables["V"& currentRow] = qryGetWords["WordName"][currentRow]>
</cfloop>
Run Code Online (Sandbox Code Playgroud)
更新:
虽然这回答了提出的问题,但Dan的回答提出了一个很好的观点.它可能不是存储信息的最佳方式.如果您详细说明您的总体目标,我们可以建议一种可能更灵活的方法.