Toggling which columns are displayed from a database query using the CFDUMP tag in ColdFusion

Readability

Toggling which columns are displayed from a database query using the CFDUMP tag in ColdFusion

The fol­low­ing exam­ple show how you can tog­gle which data­base query columns are dis­played by the <CFDUMP> tag in Cold­Fu­sion by spec­i­fy­ing the show or hide attribute.


    SELECT A.ARTISTID, A.FIRSTNAME, A.LASTNAME, A.ADDRESS, A.CITY, A.STATE
    FROM ARTISTS A



query columnList:
#getArtists.columnList#

And the out­put of the <CFDUMP> tag is as follows:

query column­List:
ADDRESS,ARTISTID,CITY,FIRSTNAME,LASTNAME,STATE

query [Fil­tered — 2 of 6 columns shown]

[Record # 1]
FIRST­NAME: Aiden
LAST­NAME: Donolan

[Record # 2]
FIRST­NAME: Austin
LAST­NAME: Weber

[Record # 3]
FIRST­NAME: Eli­cia
LAST­NAME: Kim

[Record # 4]
FIRST­NAME: Jeff
LAST­NAME: Baclawski

[Record # 5]
FIRST­NAME: Lori
LAST­NAME: Johnson

The pre­vi­ous exam­ple spec­i­fies which columns should be shown by set­ting the show attribute to FIRST­NAME, LAST­NAME. If you wanted to pre­vent cer­tain columns from being dis­played by the <CFDUMP> tag, you could set the hide attribute, as seen in the fol­low­ing example:


    SELECT A.ARTISTID, A.FIRSTNAME, A.LASTNAME, A.ADDRESS, A.CITY, A.STATE
    FROM ARTISTS A



query columnList:
#getArtists.columnList#

And the out­put of the <CFDUMP> tag is as follows:

query column­List:
ADDRESS,ARTISTID,CITY,FIRSTNAME,LASTNAME,STATE

query [Fil­tered — 4 of 6 columns hidden]

[Record # 1]
FIRST­NAME: Aiden
LAST­NAME: Donolan

[Record # 2]
FIRST­NAME: Austin
LAST­NAME: Weber

[Record # 3]
FIRST­NAME: Eli­cia
LAST­NAME: Kim

[Record # 4]
FIRST­NAME: Jeff
LAST­NAME: Baclawski

[Record # 5]
FIRST­NAME: Lori
LAST­NAME: Johnson

The following example show how you can toggle which database query columns are displayed by the <CFDUMP> tag in ColdFusion by specifying the show or hide attribute.

<cfquery name="getArtists" datasource="cfartgallery" maxRows="5">
    SELECT A.ARTISTID, A.FIRSTNAME, A.LASTNAME, A.ADDRESS, A.CITY, A.STATE
    FROM ARTISTS A
</cfquery>
 
<cfoutput>
<p>query columnList:<br/>
#getArtists.columnList#</p>
</cfoutput>
 
<cfdump var="#getArtists#"
        metaInfo="false"
        format="text"
        show="FIRSTNAME, LASTNAME" />

And the output of the <CFDUMP> tag is as follows:

query columnList:
ADDRESS,ARTISTID,CITY,FIRSTNAME,LASTNAME,STATE

query [Filtered – 2 of 6 columns shown]

[Record # 1]
FIRSTNAME: Aiden
LASTNAME: Donolan

[Record # 2]
FIRSTNAME: Austin
LASTNAME: Weber

[Record # 3]
FIRSTNAME: Elicia
LASTNAME: Kim

[Record # 4]
FIRSTNAME: Jeff
LASTNAME: Baclawski

[Record # 5]
FIRSTNAME: Lori
LASTNAME: Johnson

The previous example specifies which columns should be shown by setting the show attribute to “FIRSTNAME, LASTNAME”. If you wanted to prevent certain columns from being displayed by the <CFDUMP> tag, you could set the hide attribute, as seen in the following example:

<cfquery name="getArtists" datasource="cfartgallery" maxRows="5">
    SELECT A.ARTISTID, A.FIRSTNAME, A.LASTNAME, A.ADDRESS, A.CITY, A.STATE
    FROM ARTISTS A
</cfquery>
 
<cfoutput>
<p>query columnList:<br/>
#getArtists.columnList#</p>
</cfoutput>
 
<cfdump var="#getArtists#"
        metaInfo="false"
        format="text"
        hide="ARTISTID, ADDRESS, CITY, STATE" />

And the output of the <CFDUMP> tag is as follows:

query columnList:
ADDRESS,ARTISTID,CITY,FIRSTNAME,LASTNAME,STATE

query [Filtered – 4 of 6 columns hidden]

[Record # 1]
FIRSTNAME: Aiden
LASTNAME: Donolan

[Record # 2]
FIRSTNAME: Austin
LASTNAME: Weber

[Record # 3]
FIRSTNAME: Elicia
LASTNAME: Kim

[Record # 4]
FIRSTNAME: Jeff
LASTNAME: Baclawski

[Record # 5]
FIRSTNAME: Lori
LASTNAME: Johnson

Leave a Reply