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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With