如何在 ColdFusion 中循环查询列 [英] how to loop through Query Columns in ColdFusion
问题描述
我的 CFC 中有一个查询.该函数包含一个简单的查询.
我想这样(水平)显示我的结果集:
<上一页>名称1 名称2 名称3 名称410 20 45 62有没有办法遍历我的查询列并为此创建一个虚拟查询?
如果有人这样做,请告诉我.
只是想添加 Al Everett 的解决方案按字母顺序返回列.如果您想以与查询相同的顺序返回列名,您可以使用:
ArrayToList(qrySE.getColumnNames())
我在这里找到的:http://www.richarddavies.us/archives/2009/07/cf_columnlist.php
您可以使用它来创建一个函数来将查询输出到如下表:
I have a query in a my CFC. The function contains a simple query as such.
<cfquery name="qrySE" datasource=#mydatasource#>
SELECT
NAMES,SALARY
FROM tblTest
</cfquery>
I want to display my resultset as such (horizontally):
NAME1 NAME2 NAME3 NAME4 10 20 45 62
Is there a way to loop through the columns of my query and create a virtual query for this purpose?
If anyone has done this, please let me know.
Just wanted to add Al Everett's solution returns the columns back in alphabetical order. If you would like to get the column names back in the same order as the query you can use:
ArrayToList( qrySE.getColumnNames() )
which I found here: http://www.richarddavies.us/archives/2009/07/cf_columnlist.php
you can use this to create a function to output queries to a table like this:
<cffunction name="displayQueryAsTable" output="true">
<cfargument name="rawQueryObject" type="query" required="true">
<table >
<tr>
<cfloop list="#ArrayToList(rawQueryObject.getColumnNames())#" index="col" >
<th>#col#</th>
</cfloop>
</tr>
<cfloop query="rawQueryObject">
<tr>
<cfloop list="#ArrayToList(rawQueryObject.getColumnNames())#" index="col">
<td>#rawQueryObject[col][currentrow]#</td>
</cfloop>
</tr>
</cfloop>
</table>
</cffunction>
这篇关于如何在 ColdFusion 中循环查询列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!