[thelist] Sorting 2D Array in ColdFusion

Raymond K. Camden rcamden at allaire.com
Thu Nov 30 14:01:30 CST 2000


Michael, are you using the final release of SP2? I had no problems with the
following code:

<CFSET Foo = StructNew()>
<CFSET Foo["3800"] = 3>
<CFSET Foo["3801"] = 4>
<CFSET Foo["3900"] = 1>
<CFSET Foo["3901"] = 10>
<CFSET Foo["3903"] = 2>

<CFSET Arr = StructSort(Foo,"Numeric")>
<CFLOOP INDEX="X" FROM=1 TO="#ArrayLen(Arr)#">
	<CFOUTPUT>Foo[#arr[x]#] = #Foo[arr[x]]#<BR></CFOUTPUT>
</CFLOOP>

It correct goes 1,2,3,4,10

=======================================================================
Raymond Camden, Principal Spectra Compliance Engineer for Allaire

Email   : jedimaster at allaire.com
ICQ UIN : 3679482

"My ally is the Force, and a powerful ally it is." - Yoda


> -----Original Message-----
> From: thelist-admin at lists.evolt.org
> [mailto:thelist-admin at lists.evolt.org]On Behalf Of Michael Buffington
> Sent: Thursday, November 30, 2000 12:48 PM
> To: 'thelist at lists.evolt.org'
> Subject: RE: [thelist] Sorting 2D Array in ColdFusion
>
>
> I know I said that this worked like a charm before, but I overlooked
> something.  Seems it's not as charming as I had thought.
>
> Perhaps I don't understand the syntax to StructSort, which by allaire is
> defined as:
>
> StructSort(Base [, SortType, SortOrder, PathToSubElement])
>
> Base = the name of the structure
> SortType = (I assume) "numeric", "alpha"
> SortOrder = (I assume) "desc", "asc"
> PathToSubElement = (confusing) I think this needs something like
> StructName.Key but I try passing that and get an error - I don't
> think it's
> revelevant to my problem right now anyhow.
>
> Here's my problem:
>
> I can use:
>
> StructSort(structOrder, "Numeric", "DESC");
>
> To come up with the following:
>
> Struct. 11 key's
> NAME VALUE
> 1 3893
> 10 3897
> 11 3896
> 2 3902
> 3 3898
> 4 3894
> 5 3895
> 6 3901
> 7 3899
> 8 3900
> 9 3892
>





More information about the thelist mailing list