ColdFusion inital value of currentrow when no index specified in cfloop

25,653

Yes, queries and arrays in CF are 1-based.

The CurrentRow and RecordCount variables are properties of the query (inside a query loop they are automatically scoped).

<cfloop query="QueryName">...</cfloop> will loop through the entire query*, from 1 to QueryName.RecordCount, and the QueryName.CurrentRow index is automatically populated/incremented appropriately. Its value prior to query loop isn't used.

*(unless cfbreak/etc used)

Also to point out there is generally no need to prevent reading past the end (as above, the query loop handles it), it's only because CurrentRow+1 is being used that it's needed to avoid an error.

Share:
25,653
Rick Hodder
Author by

Rick Hodder

NET Developer, Mentor, Singer, Comedic Improv Actor and Director, and nice funny guy. @rickhodder

Updated on July 05, 2022

Comments

  • Rick Hodder
    Rick Hodder almost 2 years

    I am converting a ColdFusion application to C# (I'm a CF n00b).

    I have a script that performs a cfquery and then cfloop's through the results, and it appears to be trying to compare the current row to its following row. And it appears to be trying to make sure that it doesnt try to read past the end of the array.

    <cfquery name="qTripLegs" datasource="#sdb#">
       SELECT ...
    </cfquery>
    
    <cfloop query="qTripLegs">
        <cfif (customs_stop[currentrow] NEQ "" OR fuel_stop[currentrow] NEQ "") AND recordcount GT currentrow AND departure[currentrow] NEQ arrival[currentrow+1]>
    

    It feels like currentrow is 1-based (currentrow will have a value of 1 when it first enters the cfloop). Am I correct? I have looked in the coldfusion documentation and I dont see anything about this.

  • Rick Hodder
    Rick Hodder over 11 years
    Thanks for the help, Peter!
  • Stephane
    Stephane over 3 years
    What about a reference to the row itself ?