Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 96

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
<cfset my2darray=arraynew(2)>
<cfloop index="loopcount" from=1 to=12>
<cfloop index="loopcount2" from=1 to=2>
<cfset my2darray[loopcount][loopcount2]=(loopcount * loopcount2)>
</cfloop>
</cfloop>
<p>The values in my2darray are currently:</p>
<cfloop index="OuterCounter" from="1" to="#ArrayLen(my2darray)#">
<cfloop index="InnerCounter" from="1"to="#ArrayLen(my2darray[OuterCounter])#">
<cfoutput>
<b>[#OuterCounter#][#InnerCounter#]</b>:
#my2darray[OuterCounter][InnerCounter]#<br>
</cfoutput>
</cfloop>
</cfloop>
Nesting cfloop tags for a 3D array
For 3D arrays, you simply nest an additional
code short.)
<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, remember the following:
• You cannot add query data to an array all at once. A looping structure is often required to populate an array from
a query.
• You can reference query column data using array-like syntax. For example, myquery.col_name[1] references data
in the first row in the col_name column of the myquery query.
• Inside a
loop, you do not have to specify the query name to reference the query variables.
cfloopquery=
You can use a
tag with the following syntax to define values for array indexes:
cfset
<cfset arrayName[index]=queryColumn[row]>
In the following example, a
cfloop
tag. (This example does not set the array values first to keep the
cfloop
tag places four columns of data from a sample data source into an array, myarray.
Last updated 1/20/2012
91

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents