Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help With Sorting Results of structure output

Status
Not open for further replies.

imstillatwork

IS-IT--Management
Joined
Sep 26, 2001
Messages
1,605
Location
US
stDocCat is from tblDocManCat (Fields "Cat"(text) and "CatID"(autonum))

When I loop the structure below(stDocCat), I want to output to be sorted by "cat". As it is now, output is sorted by CatID, so my output is not alphabetical.
Do i need to use an array to be able to sort this properly?
The structure takes the index to output the

So what I want, is, that the output of the cfloop is sorted by "cat", not "catID".
as it is, it is not friendly to the eye. I want the output to be alphabetical.

any ideas?

I may not be explaining it good, if you email me, I may be able to allow you to view what I am working on.

Kevin




Below is my code.



<!---
======================
== ARTICLE MENU ==
======================
--->
<cfif isDefined(&quot;attributes.catID&quot;)>
<cfquery name=&quot;getdoclist&quot; datasource=&quot;intranet&quot;>
SELECT *
FROM tblDocMan
WHERE tblDocMan.CatID = #attributes.CatID#
AND tblDocMan.typeID = #attributes.Type#
ORDER BY title ASC
</cfquery>
</cfif>
<!---Use Structure in Application.cfm--->
<cfloop collection=&quot;#stDocCat#&quot; item=&quot;index&quot;>
<cfoutput>
<br>&nbsp;&nbsp;&nbsp;<a href=&quot;/index.cfm?loc=docs&docact=list&type=#attributes.type#&catID=#index#&quot;>#stDocCat[index]#</a>
</cfoutput>

<cfif isDefined(&quot;attributes.catID&quot;)>
<cfif attributes.catID eq #index#>
<span class=&quot;bold&quot;>:.</span>
<cfif getdoclist.recordcount eq 0>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>:</b> there is nothing here
<cfelse>
<cfoutput query=&quot;getdoclist&quot;>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>:</b> <a href=&quot;/index.cfm?loc=docs&type=#attributes.type#&docact=view&CatID=#attributes.catID#&DocID=#docID#&quot;><span class=&quot;docmenu&quot;>#Title#</span></a>
</cfoutput>
<br>
</cfif>
</cfif>
</cfif>


</cfloop> IF YOU DON'T KNOW HOW A TAG WORKS...
...DOWNLOAD THE CFML REFERENCE!
 
I had this problem as well and the only way that i found to get around this was to have a list with the index of the structure then to loop over this list but to output the information from the structure(if this makes sense at all)

<!--- the bit that does the sorting --->
<CFSET Session.SortList = ListSort(StructKeyList(Session.Cart),&quot;textNoCase&quot;)>

then the information is output using:

<CFLOOP LIST=&quot;#Session.SortList#&quot; INDEX=&quot;i&quot;>
#Session.Cart#
</cfloop>

this was the only way that i could find of doing this it seems to work alright i am using CF 4, but with CF 5 there is a StructSort function that will do the same thing as above, i haven't used that though i am afraid so can't offer any guidance on that one !
 
Thanks.
For now, I'm just going to loop a query in a query... the data is so small that performace will be fine. I would still like to know how to do this, as futute projects may require it!

Kevin IF YOU DON'T KNOW HOW A TAG WORKS...
...DOWNLOAD THE CFML REFERENCE!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top