
92
DEVELOPING
COLDFUSION 9 APPLICATIONS
The CFML Programming Language
Las
t
upda
te
d 8/5/2010
<!--- Do the query --->
<cfquery name="test" datasource="cfdocexamples">
SELECT Emp_ID, LastName, FirstName, Email
FROM Employees
</cfquery>
<!--- Declare the array --->
<cfset myarray=arraynew(2)>
<!--- Populate the array row by row --->
<cfloop query="test">
<cfset myarray[CurrentRow][1]=Emp_ID>
<cfset myarray[CurrentRow][2]=LastName>
<cfset myarray[CurrentRow][3]=FirstName>
<cfset myarray[CurrentRow][4]=Email>
</cfloop>
<!--- Now, create a loop to output the array contents --->
<cfset total_records=test.recordcount>
<cfloop index="Counter" from=1 to="#Total_Records#">
<cfoutput>
ID: #MyArray[Counter][1]#,
LASTNAME: #MyArray[Counter][2]#,
FIRSTNAME: #MyArray[Counter][3]#,
EMAIL: #MyArray[Counter][4]# <br>
</cfoutput>
</cfloop>
This example uses the query object built-in variable CurrentRow to index the first dimension of the array.
Array functions
The following functions are available for creating, editing, and handling arrays:
Function
Description
ArrayAppend
Appends an array element to the end of a specified array.
ArrayAvg
Returns the average of the values in the specified array.
ArrayClear
Deletes all data in a specified array.
ArrayDeleteAt
Deletes an element from a specified array at the specified index and resizes the array.
ArrayInsertAt
Inserts an element (with data) in a specified array at the specified index and resizes the array.
ArrayIsDefined
Returns True if the specified array is defined.
ArrayIsEmpty
Returns True if the specified array is empty of data.
ArrayLen
Returns the length of the specified array.
ArrayMax
Returns the largest numeric value in the specified array.
ArrayMin
Returns the smallest numeric value in the specified array.
ArrayNew
Creates an array of specified dimension.
ArrayPrepend
Adds an array element to the beginning of the specified array.
ArrayResize
Resets an array to a specified minimum number of elements.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...