I have situation where I have to compare values from structure and array. My structure is created and populated with values from query. Array is created and populated with values from .csv file. Now I need to loop through each of them, compare specific values and then if they match move those values in the list. I will have to use that list later to update/insert records in two different tables. Here is my code for structure:
<cfquery name="getRecords" datasource="test">
Select s.ID, f.OLDID, s.USER_NUMBER, s.STATUS, f.DINING
From USERS s
Left Outer Join FIELDS f
ON s.ID = f.OLDID
</cfquery>
<cfset myStruct = StructNew()>
<cfloop query="getRecords">
<cfset myStruct[USER_NUMBER] = {id1=ID,id2=OLDID,st=STATUS,din=DINING}>
</cfloop>
Here is my code that creates array from .csv file:
<cffile action="read" file="#whfile#" variable="myfile">
<cfset myarray = ListToArray(myfile, chr(13))>
<cfset cnt = ArrayLen(myarray)>
<cfloop index="i" from="1" to=#(cnt)# step="1">
<cfset myrow = #replace(myarray[i],chr(10),'')#>
<cfset myrow = ListToArray(myrow,",",true)>
//Here I can loop through array and grab value from specific column
</cfloop>
I never done comparing from two different arrays or structures before. What is the best way to compare values from these two lists. For example I would have to compare USER_NUMBER from my struct and myrow[1] that represent column 1 which holds USER_NUMBER populated from .csv file. If anyone can help with this problem please let me know. Thank you.