htmlcoldfusioncfoutput

ColdFusion: how to access dynamic column names


ColdFusion 2018.

I ran a pivot query in Oracle that generated following column headers.

I need to output result of this query into html table.

How do I access these column headers?

enter image description here


Solution

  • Like this, if you want the columns in alphabetetical order:

    <table>
    <tr>
    <cfoutput>
    <cfloop list="#queryname.columnlist#" index="header">
    <td>#header#</td>
    </cfloop>
    </cfoutput>
    </tr>
    

    Like this, if you want the columns in the order they appear in the query:

    <table>
    <tr>
    <cfoutput>
    <cfloop array="#queryname.getcolumnlist()#" item="header">
    <td>#header#</td>
    </cfloop>
    </cfoutput>
    </tr>