2

我正在尝试在cfscript. 我想我有它,但它的查询循环到无穷大。

有人可以告诉我以下有什么问题:

<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>

该查询current_message返回一条记录,因此它应该只循环一次。

感谢帮助!

4

1 回答 1

11

You have your condition around the wrong way.

It should be:

variables.intRow LTE variables.allRows 

I suspect current_message actually 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 like variables.allRows LTE variables.intRow is evaluating to false, which suggests variables.allRows is greater than one when you first start.

In regards to this:

The query current_message returns a single record, so this should loop once only.

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:

for (row in recordset){
    // row is a struct keyed on each column name, the values being the value for that column/row
}
于 2012-10-06T12:46:45.273 回答