I a loop nested in a loop that drives a query that kind of walks backwards out
by a commodity classification then by region classification... so essentially
people search for a narrow commodity in a narrow region and as the loop loops
it gets very relevant data moving to not so relevant data... so each query
that is executed in a particular iteration of the loop is sorted
alphabetically... so for example i am querying a contacts db and i want to get
the first and last names... i make a structure with fname and lname then
append that structure to the array... Since the series of loop driven queries
returns a large number of records i want this list sorted by last name to make
the list more easily readable and accessible for the end user... attached is
the code used to generate the array... Anyone have any ideas how I can sort
this??? One idea i had was to just return a list of contact IDs and at the end
I can do one final query to return all the contacts and then i could just use
ORDER BY in my SQL but I just wanted to know if anyone knew of a way to sort
that array and avoid another call to the db...

<cfset conCount = 0>
<cfset conRecords = arrayNew(1)>
<cfset CONID_SELECTED = "0">

<cfset timesThruCD = 1>
<cfloop list="#CD#" delimiters="|" index="rgncode">

<cfset timesThruHS = 1>
<cfset workingHS = HS_CODE>
<cfloop from="1" to="#evaluate(len(HS_CODE)/2)#" index="loopPos">

<cfif timesThruHS EQ 1>
<cfset sqlHS = "AND LNK_HS_CODE LIKE '" & workingHS & "%'">
<cfelse>
<cfset sqlHS = "AND LNK_HS_CODE = '" & workingHS & "'">
</cfif>

<cfif timesThruCD EQ 1 AND listLen(CD,"|") GT 1>
<cfset sqlCD = "AND LNK_SUB_CODE = '" & rgncode & "'">
<cfelse>
<cfset sqlCD = "AND LNK_CD_CODE = '" & rgncode & "'">
</cfif>

<cfquery name="getQuad4" datasource="#SQLDatabase#">
SELECT DISTINCT CI_Contacts.CI_ID,
CO_Company.CO_Name,
CI_Contacts.CI_FName,
CI_Contacts.CI_LName,
CI_Contacts.CI_Phone,
CI_Contacts.CI_Email
FROM LNK_CI_HS INNER JOIN CO_Company
INNER JOIN CI_Contacts ON CO_Company.CO_ID = CI_Contacts.CI_CO_ID ON
LNK_CI_HS.LNK_CI_ID = CI_Contacts.CI_ID
INNER JOIN LNK_CI_CD ON CI_Contacts.CI_ID = LNK_CI_CD.LNK_CI_ID
WHERE 1 = 1
AND CI_ID NOT IN (#CONID_SELECTED#)
#preserveSingleQuotes(sqlHS)#
#preserveSingleQuotes(sqlCD)#
ORDER BY CI_LNAME
</cfquery>

<cfif getQuad4.recordcount>
<cfset CONID_SELECTED =
listAppend(CONID_SELECTED,valueList(getQuad4.CI_ID ))>
<cfoutput query="getQuad4">

<cfscript>
CI = structNew();
CI.CO_NAME = "#CO_NAME#";
CI.CI_ID = "#CI_ID#";
CI.CI_FNAME = "#CI_FNAME#";
CI.CI_LNAME = "#CI_LNAME#";
CI.CI_PHONE = "#CI_PHONE#";
CI.CI_EMAIL = "#CI_EMAIL#";
</cfscript>
<cfset dummy = arrayAppend(conRecords,CI)>
<cfset conCount = conCount + 1>
</cfoutput>
</cfif>

<cfif len(workingHS) GT 2>
<cfset workingHS = LEFT(workingHS,evaluate(len(workingHS)-2))>
</cfif>

<cfset timesThruHS = 2>

</cfloop>

<cfset timesThruCD = 2>

</cfloop>