当查询列是变量时从 cfquery 获取值
我被困住了...不记得如何进行这项工作。代码:
<cfquery name = "getsomething>
select a, b, c
from d
where id = '1'
</cfquery>
<cfloop collection="#arguments#" item="argument">
<cfif #StructFind(arguments, argument)# neq #getsomething.argument[0]#><!--- here's the problem --->
do something
</cfif>
</cfloop>
查询返回一条记录;我需要获取该记录的每一列的值。列名是一个变量(参数)。我需要替换什么语法
#getsomething.argument[0]#
?谢谢。
I'm stuck... can't remember how to make this work. The code:
<cfquery name = "getsomething>
select a, b, c
from d
where id = '1'
</cfquery>
<cfloop collection="#arguments#" item="argument">
<cfif #StructFind(arguments, argument)# neq #getsomething.argument[0]#><!--- here's the problem --->
do something
</cfif>
</cfloop>
The query returns one record; I need to get the values of each column for that record. The column name is a variable (argument). What syntax do I need to replace
#getsomething.argument[0]#
? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要进行一些调整:
我看到您正在使用“collection”参数进行循环。这意味着您有一个像这样的数据结构:
您可以看到在这种情况下值并不重要 - 重要的是通过使用“集合”参数,您正在使用一个结构。有点不正确,但让我们继续假设。
您不希望动态评估参数的值,您需要键 - 它们映射到您的列,因此像这样循环:
然后,以下代码有效:
请注意,在这个答案中,我已将查询索引从 0 更改为 1:cfquery 数组是从 1 开始的,因此第一行不是 [0],而是 [1]。
You need to make a couple of adjustments:
I see you are looping using the "collection" argument. This implies you have a data structure like so:
You can see that the values do not matter in this case--what matters is that by using the "collection" argument, you are working with a struct. Somewhat incorrect, but let's move forward with the assumption.
You do not want the value of your arguments dynamically evaluated, you want the keys--they map to your columns, so loop like this:
then, the following code works:
Note that in this answer, I've changed your query index from 0 to 1: cfquery arrays are 1-based, so the first row is not [0], but [1].