Thursday, December 14, 2006

Looping query output

There are a few way to output query, CFloop or CFOutput. When you want to get fancy you can use cfloop and reference the query like an array for example:

<CFLOOP INDEX="z" FROM="1" TO="#Query.recordcount#">
#query.column[z]#
</CFLOOP>

Now, here is where the fun comes in. I was writing an app where I needed to see what was in the next row so I could do something with the current row. I had this in my code:

#query.column[z+1]#

This worked perfectly fine and I had no issues. However, I forgot to add an if to make sure I was not on the last row before I checked the next row. Instead of getting an error I got a strange response. I actually got a blank result. So, I then got curious. So, I did this:

#IsDefined(query.column[1])# -- #query.column[1]#

I got this as a response:

NO -- 123

In conclusion I discovered 2 things:

1: isDefined on a query column using array syntax always returns no.
2: Query column output using array syntax can reference a nonexistent row and not error.

No comments: