10 Little Ones: For in loop for Queries (#2)
March 7, 2012
ColdFusion 10, now in public beta, adds for-in loops for query recordsets. The variable name in the for loop will reference each column by the column name.
The currentrow can be referenced by queryname.currentrow as seen in the example below. Same for recordcount.
getArt = new query( sql="SELECT artName, price FROM Art" ).execute().getResult();
for ( row in getArt ) {
writeOutput( "<li>" & getArt.currentRow & ": " & row.artName & " " & row.price & "</li>");
}
5 Comments
Some comments have been lost over the years due to moving hosts.
By: Gary F 03/08/2012 7:30 AM