CFLib.org – Common Function Library Project

queryRowToList(query[, queryrow][, delim])

Last updated August 06, 2004

author

Tim Sloan

Version: 1 | Requires: CF5 | Library: DataManipulationLib

Description:
Use this function to take row of data from a query and create a simple list from that row. Useful when you are querying a text file as a datasource and the columns are listed in the first row.

Return Values:
Returns a string.

Example:

... any cfquery here name="qryExample" ...

<cfset listOfData = queryRowToList(qryExample)>
<cfset listOfData = queryRowToList(qryExample, 100)>
<cfset listOfData = queryRowToList(qryExample, 1000, "|")>

Parameters:

Name Description Required
query The query to examine. Yes
queryrow Row to use. No
delim Delimiter to use. No

Full UDF Source:

/**
 * Function to take a single row from a query and generate a list.
 * 
 * @param query      The query to examine. (Required)
 * @param queryrow      Row to use. (Optional)
 * @param delim      Delimiter to use. (Optional)
 * @return Returns a string. 
 * @author Tim Sloan (tim@sloanconsulting.com) 
 * @version 1, August 6, 2004 
 */
function queryRowToList(query){
    var queryrow = 1;
    var j = 1;
    var querycols = listToArray(query.columnList);
    var delim = ",";
    var listReturn = "";
    if(arrayLen(arguments) GT 1) queryrow = arguments[2];
    if(arrayLen(arguments) GT 2) delim = arguments[3];
    for(j = 1; j lte arraylen(querycols); j = j + 1){
        listReturn = ListAppend(listReturn, query[querycols[j]][queryrow], delim);
    }        
    return listReturn;
}

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