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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with glossary

Status
Not open for further replies.

peterswan

Programmer
Sep 25, 2002
263
US
Hello,
I need to create a glossary that has a group header for each letter of the alphabet and each acronym and its definition listed under the correct header for the first letter of the acronym. Within each group, I'd like to have the acronyms in alphabetical order.

What I'd like to do is create an array and add the acronyms and their definitions into the array, then sort the array alphabetically, and then loop through the array to display the values.

So far I've created the array and its values, however, I can't get it to sort by text because I've created the array like this:

<cfset acronyms = ArrayNew(1)>

<cfset acronyms[ArrayLen(acronyms) + 1][1] = "OU">
<cfset acronyms[ArrayLen(acronyms)][2] = "Oklahoma University">
<cfset acronyms[ArrayLen(acronyms) + 1][1] = "UK">
<cfset acronyms[ArrayLen(acronyms)][2] = "University of Kansas">

The ArraySort function doesn't know how to sort anything that has two elements for each row. What I want it to do is sort by the first element (the acronym). Then somehow I want to loop through it.

What I'm doing now is looping through the alphabet and then outputting the values of the array like this:

<cfloop list="#alphabet#" index="idx">
<cfoutput>#idx#<br></cfoutput>
<cfloop from="1" to="#ArrayLen(acronyms)#" index="idx2">
<cfif left(acronyms[idx2][1], 1) is idx>
<cfoutput>#acronyms[idx2][1]# &nbsp; #acronyms[idx2][2]#<br></cfoutput>
</cfif>
</cfloop>
</cfloop>

This works fine except:

1. It won't sort the values within each alphabet letter.
2. It's not very efficent. I have to loop through the entire list of acronyms for each letter of the alphabet.

What I'd like to do is append each new acronym / definition onto the array, then sort it by text, then loop through it to display it.

Any ideas? [smile]

Peter

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top