I’m trying to loop a query in cfscript. I think I have it, but it the query loops into infinity.
Can someone tell me what is wrong in the following:
<cfscript>
// loop single msg
variables.allRows = current_message.recordcount;
for ( variables.intRow = 1 ; variables.allRows LTE variables.intRow ; variables.intRow = variables.intRow + 1 ){
variables.msg_id_viewed = current_message[ "com_msg_id" ][ variables.intRow ];
variables.msg_app_alias = current_message[ "com_app_alias" ][variables.intRow];
variables.msg_img_ext = current_message[ "com_img" ][ variables.intRow ];
}
</cfscript>
The query current_message returns a single record, so this should loop once only.
Thanks for help!
You have your condition around the wrong way.
It should be:
I suspect
current_messageactually has multiple rows. Did you actually check, or did you simply run on the assumption that that’s what you’re expecting? Because it looks to me likevariables.allRows LTE variables.intRowis evaluating tofalse, which suggestsvariables.allRowsis greater than one when you first start.In regards to this:
If there’s only one row – and you know this to be the case – why are you looping?
That said, what version of ColdFusion are you on? In CF10 one can loop over a recordset with the for/in construct, thus: