Looping Columns In Coldfusion Along With Values In Correct Order
Instead of hardcoding the columns from a query into a table I prefer to do it dynamically. This is code I tweaked from another source. What I want to do is not only get the Columns
Solution 1:
Something I learned from other people's answers on these forums is that ColdFusion has a function called getColumnList(). It returns an array of the column names in the order they appear. I just ran this code to verify it.
<cfquery name="x" datasource="burns">
select1 b, 2 a
from dual
</cfquery>
<cfdump var="#x.getcolumnlist()#" metainfo="no">
It returned an array showing b, then a.
For displaying your column headers, you simply loop through this array. Displaying the data would be slightly more complicated. I would do something like this:
<cfoutputquery="q1"><cflooparray="#q1.getcolumnlist()#"index = "arrayElement">
#q1[arrayElement][currentrow]#
closing tags
Solution 2:
This answer seems too obvious to be the answer to your requirement, but I can't think what else you might mean. One loops over a recordset via the <cfloop>
tag:
<cfloopquery="showDeletedData"><!--- loop rows---><cflooparray="#employeemeta#"index="col"><!--- loop columns---><cfoutput>#showDeletedData[col][currentRow]#</cfoutput><!--- output value for the row/column ---></cfloop></cfloop>
Is that what you're asking?
Post a Comment for "Looping Columns In Coldfusion Along With Values In Correct Order"