queryColumnToArray(query, column)
Last updated July 22, 2005
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;
}
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