User Guide

110 Developing Web Applications with ColdFusion
<P>My3darray’s values are currently:
<CFLOOP INDEX="Dim1"
FROM="1" TO="#ArrayLen(my3darray)#">
<CFLOOP INDEX="Dim2"
FROM="1" TO="#ArrayLen(my3darray[Dim1])#">
<CFLOOP INDEX="Dim3" FROM="1"
TO="#ArrayLen(my3darray[Dim1][Dim2])#">
<CFOUTPUT>
<B>[#Dim1#][#Dim2#][#Dim3#]</B>:
#my3darray[Dim1][Dim2][Dim3]#<BR>
</CFOUTPUT>
</CFLOOP>
</CFLOOP>
</CFLOOP>
Populating an Array from a Query
When populating an array from a query, keep the following things in mind:
Query data cannot be added to an array all at once. A looping structure is
generally required to populate an array from a query.
Query column data can be referenced using array-like syntax. For example,
myquery.col_name[1] references data in the first row in the column col_name.
You can use a CFSET tag to define values for array indexes, as in the following example:
<CFSET arrayname[
x
]=
queryname.column
[
row
]>
In the following example, a CFLOOP is used to place four columns of data from a
sample data source into an array, "myarray."
<!--- Do the query --->
<CFQUERY NAME="test" DATASOURCE="cfsnippets">
SELECT EMPLOYEE_ID, LASTNAME,
FIRSTNAME, EMAIL
FROM EMPLOYEES
</CFQUERY>
<!--- Declare the array --->
<CFSET myarray=ArrayNew(2)>
<!--- Populate the array row by row --->
<CFLOOP QUERY="TEST">