Thursday, 24 January 2008

Coldfusion query column to array

The normal method of converting Coldfusion query column to array is to use a valuelist and list to array:

the_array=listtoarray("#valueList(the_query.the_column)#")

But this strips out any cells with empty strings in. To get around this use:

the_array=duplicate(the_query[column_name]);
ArrayPrepend(the_array,the_query[column_name][1]);

why the ArrayPrepend() call afterwards? Because CF arrays start at 1 and Java (the underlying language) starts at 0, so the duplicate function misses off the first row of the column.

nice.