Description

This function calls each row of the query provided.

Returns

None

Category

Query functions

History

New in Adobe ColdFusion (2016 release)

See also

QuerySortQueryFilterQueryKeyExists

Syntax

void QueryEach(Object query, UDFMethod func)

Parameters

Parameter Description
query (Required) Query to be iterated over.
func (Required) Function to be called with each row of the query.

Example

<cfscript>
               qoptions = {result="myresult", datasource="cfbookclub", fetchclientinfo="yes"};
               sampleQuery = QueryExecute("select * from books order by bookid", [] ,qoptions);
               
               function printQuery(any Obj){
                              WriteDump(Obj);
               }
               WriteOutput("QueryEach: ");
               QueryEach(sampleQuery, printQuery);
</cfscript>

The script loops through each item in the query.

Using member function

<cfscript>
       myResult=QueryExecute("SELECT * FROM EMPLOYEES",[],{datasource="cfdocexamples"});
       // Execute the function to call each row and return the values of Location
       myResult.each(function(count){
             myList=#count.LOCATION#;
             WriteOutput(myList);
       });
</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