CFLib.org – Common Function Library Project

queryColumnToArray(query, column)

Last updated July 22, 2005

author

Peter J. Farrell

Version: 1 | Requires: CF5 | Library: DataManipulationLib

Description:
Takes a selected column of data from a query and converts it into an array.

Return Values:
Returns an array.

Example:

<cfset qry = QueryNew("things,stuff") />
<cfset queryAddRow(qry)>
<cfset QuerySetCell(qry,"things", "A") />
<cfset QuerySetCell(qry,"stuff", "a1") />
<cfset queryAddRow(qry)>
<cfset QuerySetCell(qry,"things", "B") />
<cfset QuerySetCell(qry,"stuff", "b2") />
<cfset queryAddRow(qry)>
<cfset QuerySetCell(qry,"things", "C") />
<cfset QuerySetCell(qry,"stuff", "c3") />

<cfset my_array = queryColumnToArray(qry, "things") />
<cfdump var="#my_array#" />

Parameters:

Name Description Required
query The query to scan. Yes
column The name of the column to return data from. Yes

Full UDF Source:

/**
 * Takes a selected column of data from a query and converts it into an array.
 * 
 * @param query 	 The query to scan. (Required)
 * @param column 	 The name of the column to return data from. (Required)
 * @return Returns an array. 
 * @author Peter J. Farrell (pjf@maestropublishing.com) 
 * @version 1, July 22, 2005 
 */
function queryColumnToArray(qry, column) {
	var arr = arrayNew(1);
	var ii = "";
	var loop_len = arguments.qry.recordcount;
	for (ii=1; ii lte loop_len; ii=ii+1) {
		arrayAppend(arr, arguments.qry[arguments.column][ii]);
	} 
	return arr;
}
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