Iterates over query rows and passes each row per iteration to a callback function
queryEach(query, function(row [, currentRow] [, query] ){} [, parallel] [, maxThreads])
returns void
query.each(function(row [, currentRow] [, query] ){} [, parallel] [, maxThreads])
Name | Type | Required | Default | Description |
---|---|---|---|---|
query | query | Yes | query to loop over | |
callback | any | Yes | Closure or a function reference that will be called for each of the iteration. | |
parallel | boolean | No | Lucee4.5+ Executes closures parallel | |
maxThreads | numeric | No | 20 | Lucee4.5+ Maximum number of threads executed If parallel argument is set to false it will be ignored |
| Name | Type | Required | Description | | — | — | — | — | | row | struct | No | A struct with all of the columns for the current iteration | currentRow | numeric | No | The value for the current iteration | query | query | No | A reference of the original struct
ACF2016+ and Lucee5+
<cfscript>
news = queryNew("id,title",
"integer,varchar", [{
"id": 1,
"title": "Dewey defeats Truman"
}, {
"id": 2,
"title": "Man walks on Moon"
}]
);
function newsRow(row) {
writeOutput("<tr>");
writeOutput("<td>#row.id#</td>");
writeOutput("<td>#row.title#</td>");
writeOutput("</tr>");
}
</cfscript>
<table>
<cfscript>
queryEach(news,newsRow);
</cfscript>
</table>
2 Man walks on Moon
Lucee5+
<cfscript>
news = queryNew("id,title",
"integer,varchar", [{
"id": 1,
"title": "Dewey defeats Truman"
}, {
"id": 2,
"title": "Man walks on Moon"
}]
);
function newsRow(row) {
writeOutput("<tr>");
writeOutput("<td>#row.id#</td>");
writeOutput("<td>#row.title#</td>");
writeOutput("</tr>");
}
</cfscript>
<table>
<cfoutput>#queryEach(news,newsRow)#</cfoutput>
</table>
2 Man walks on Moon