-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of David Hagen
Sent: Thursday, June 07, 2001 7:40 AM
To: [EMAIL PROTECTED]
Subject: Help with ArraysI need help sorting the array alphabetically by last name. Here is the code:
<CFQUERY NAME="test" DATASOURCE="sales">
SELECT id, fname, lname
FROM reps
</CFQUERY><CFSET myarray=ArrayNew(2)>
<CFLOOP QUERY="TEST">
<CFSET myarray[CurrentRow][1]=test.id[CurrentRow]>
<CFSET myarray[CurrentRow][2]=test. fname[CurrentRow]>
<CFSET myarray[CurrentRow][3]=test.lname[CurrentRow]>
</CFLOOP><CFSET Total_Records=Test.RecordCount>
<CFLOOP INDEX="Counter" FROM=1 TO="#Total_Records#">
<CFOUTPUT>
ID: #MyArray[Counter][1]#,
FIRST NAME: #MyArray[Counter][2]#,
Last NAME: #MyArray[Counter][3]#
<BR>
</CFOUTPUT>
</CFLOOP>- Dave
Title: Message
Rather
than stick your query data in your final arrays to begin with, take some
intermediary steps :
(pseudocode)
<cfset lstArr = "">
<cfquery name="query">
<cfset strArr = lname & "|"
fname & "|" & id>
<cfset lstArr =
ListAppend(lstArr, strArr)>
</cfquery>
<cfset tempArray =
ListToArray(lstArr)>
<cfset tempArray =
ArraySort(tempArray)>
<CFSET myarray=ArrayNew(2)>
<cfloop index="i" from="1"
to="#ArrayLen(tempArray)#">
<cfset myArray[i] =
ListToArray(tempArray[i])>
</cfloop>
This
code probably isn't exact, but you get the idea:
1. convert each row into a string, using some
safe delimiter.. whatever you want to sort by, put first in the string.. each of
these strings is an element in a one-dimensional array
2. using ArraySort, sort the array (sorting the
entire query recordset)
3. loop over your temp array, and extract your
information, and place it into the final array
---
Billy Cravens
HR Systems, Sabre
- Help with Arrays David Hagen
- Re: Help with Arrays Jeff Mayfield
- RE: Help with Arrays Billy Cravens
- RE: Help with Arrays David Hagen
- RE: Help with Arrays Jeff Mayfield
