CFLib.org – Common Function Library Project

queryToTableDump(queryData)

Last updated June 9, 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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson