CFLib.org – Common Function Library Project

queryToTableDump(queryData)

Last updated June 10, 2011

author

Jared Rypka-Hauer

Version: 2 | Requires: CF8 | Library: UtilityLib

Description:
This UDF takes a query as an argument and dumps out the contents of the query in a table, columns in TH tags and data in TD tags, for the simple purpose of examining the data in a page. Not intended for production use, it's handy for the beginning stages of laying out a page based on someone else's query or dumping the contents of a cfdirectory or cfpop call in situations where significant formatting is not necessary.

Return Values:
Returns a string.

Example:

<cfdirectory action="list" directory="#expandPath('.')#" name="dirList" />
<cfoutput>#queryToTableDump(dirList)#</cfoutput>

Parameters:

Name Description Required
queryData Query to display. Yes

Full UDF Source:

<!---
 Simple table-based datadump from any query
 
 @param queryData      Query to display. (Required)
 @return Returns a string. 
 @author Jared Rypka-Hauer (jared@web-relevant.com) 
 @version 2, June 9, 2011 
--->
<cffunction name="queryToTableDump" access="public" returntype="string" output="false">
    <cfargument name="queryData" type="query" required="true" />
    <cfset var theQuery = arguments.queryData>
    <cfset var columns = arraytolist(theQuery.getMeta().getColumnLabels())>
    <cfset var theResults = "">
    <cfset var c = "">
    <cfset var i = "">
    <cfsavecontent variable="theResults">
        <cfoutput>
            <table border="1" cellpadding="0" cellspacing="0" align="left">
            <tr>
            <cfloop list="#columns#" index="c">
                <th>#c#</th>
            </cfloop>
            </tr>
            <cfloop from="1" to="#theQuery.recordCount#" index="i">
                <tr><cfloop list="#columns#" index="c">
                    <td><cfif len(theQuery[c][i])>#theQuery[c][i]#<cfelse> </cfif></td></cfloop>
                </tr>
            </cfloop>
            </table>
        </cfoutput>
    </cfsavecontent>
    <cfreturn theResults />
</cffunction>

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson