Description

This function converts the values of a specified column of a query into an array.

Returns

An array of column values.

Category

History

New In Adobe ColdFusion (2016 release)

Syntax

ValueArray (Object query, String columnName)

Parameters

Parameter Req/Opt Description
query Required The query to be iterated over.
columnName Required The name of the column whose values you want to return.

Example

<cfscript>
       // Execute a query from table Orders
       myQuery=QueryExecute("select * from orders",[],{datasource="cfartgallery"});
       // Convert the values in the column Address into the array myColumn
       myColumn=ValueArray(myQuery,"Address");
       // Display array values
       writedump(myColumn);
</cfscript>

Output

Note:

Before the implementation of ValueArrray member function, you could also use query["column"] to convert the column values into an array, as shown below:

<cfscript>
  a=[];
  q = queryNew("foobar", "", [["foo"],["bar"]]);
  a.append(q["foobar"], true);
  writeDump(a);//returns same result as q.valueArray("foobar")
</cfscript>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy