CFLib.org – Common Function Library Project

queryColumnToArray(query, column)

Last updated July 22, 2005

Version: 1 | Requires: ColdFusion 5 | Library: DataManipulationLib

 
Rated 1 time(s). Average Rating: 5.0

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

Return Values:
Returns an array.

Example:

view plain print about
<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:

view plain print about
<cfscript>
/**
 * 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;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Dave Anderson Dave Anderson added
iniToStruct
20 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
20 day(s) ago

Richard Richard added
dice
22 day(s) ago

Isaac Dealey Isaac Dealey added
getRelative
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 22 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson