Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ColdFusion inital value of currentrow when no index specified in cfloop

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.

like image 538
Rick Hodder Avatar asked Jan 08 '13 23:01

Rick Hodder


1 Answers

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.

like image 106
Peter Boughton Avatar answered Sep 23 '22 17:09

Peter Boughton