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 1

<cfscript>
    myQuery = queryNew("id,name,amount","Integer,Varchar,Integer", 
                [ 
                        {id=1,name="One",amount=15}, 
                        {id=2,name="Two",amount=18}, 
                        {id=3,name="Three",amount=32},
                        {id=4,name="Four",amount=53}
                ]);
   // Convert the values in the column Address into the array myColumn
    arrayList=ValueArray(myQuery,"name")
    
   // Display array values
   writeDump(arrayList)
</cfscript>

Output

ValueArray1

Example 2

<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

ValueArray

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