Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
ultrafresh #1
Sorting an Array containing a structure...
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>
ultrafresh Guest
-
Sorting a Structure
I must be missing something as I can't seem to figure out how to sort a structure based on the key name, not key value. I'm trying to create a... -
Sorting array vs sorting paginated array
....pulling in a long list of photos in a gallery, and I have a sort function working within the pages of data fine. I need to bring it back out of... -
Array Sorting
Hey everyone, I figured someone out there must have come across the need for this before, so rather than continue banging my head against the... -
structure/array gurus - a challenge for you
Your mission, should you choose to accept it, is to help this dizzy array/structure newbie figure his way through this minefield: I am trying to... -
Array Structure for Application State Variable?
An Array is an object. All you do is store it wherever you want to, and fetch it back casting it as an Array of whatever data type you have in...



Reply With Quote

