Access queries as structs in ColdFusion

Tags: 

A small tip, but a very, very useful one nonetheless. Did you know that in ColdFusion you don't have to loop through a query to access specific elements of the query? I've been developing in CFML for several years and was unaware of this. It's great! Instead of having to go through the hassle of looping an array just to find one field, if you know the field and row number you can just do this:

<cfset variable = query[column_name][row_number] />

e.g.:

<cfset variables.product_name = variables.q_products[name][5] />

Thanks to Ben Nadel for that.

Sometimes you just feel like a complete neophyte. I wonder what other useful tricks lie beneath the surface?

How to reply

Care to add your own 2 cents? Let me know via Twitter or my contact page.