For request:
<cfquery name="qMyQuery" datasource="MyDatasource"> SELECT * FROM myTable </cfquery> <cfscript> cols = qMyQuery.columnList; colCount = ListLen(cols); </cfscript>
For structure:
<cfset stStruct = { key1="Value1", key2="Value2", key3="Value3" } /> <cfscript> cols = structKeyList(stStruct); colCount = structCount(stStruct); </cfscript>
Based on either you can do something like this:
<table> <thead> <tr> <cfloop list="#cols#" delimiters="," index="c"><th>#c#</th></cfloop> </tr> </thead> <tbody> <tr> <cfloop list="#cols#" delimiters="," index="c"><td>#stStruct[c]#</td></cfloop> </tr> <cfoutput query="qMyQuery"> <tr> <cfloop list="#cols#" delimiters="," index="c"><td>#qMyQuery[c][qMyQuery.currentRow]#</td></cfloop> </tr> </cfoutput> </tbody> </table>
source share