3
votes

I have my query outputted in structure. Then I have my array where I loop through. I want to compare value from my structure and my array. First to compare array value 1 and key of my structure, if they are the same I have another if statement where I want to compare array value 23 and my structure value code, if they are not the same I store array value 1 in the list. Here is my code that I have so far:

<!--- loop that populates myStruct --->
<cfloop query="getCustomers">
    <cfset myStruct[Cutomer_Number] = {id1=ID,code=CS_CODE}>
</cfloop>

<cfloop index="i" from="1" to="#(cnt)#" step="1">   
    <cfif len(trim(myarray[i])) GT 0>
        <cfset myrow = #replace(myarray[i],chr(10),'')#>
        <cfset myrow = ListToArray(myrow,",",true)>

        <!--- this if statement works where I compare my key and row 1 from    array --->
        <cfif structKeyExists(myStruct,myrow[1])>
<!--- here I want to check if CS_CODE and row 2 are different--->
            <cfif structFindValue(myStruct.CS_CODE,myrow[2])>
                <cfoutput>#count# - #myrow[1]# - #myrow[2]#</cfoutput><br>
            </cfif>
        </cfif>
        <cfset count++>
    </cfif>
</cfloop>

I'm getting an error that CS_CODE variable does not exist. I'm definitely doing something wrong when I try to access value from my struct and also structFindValue might not be something that I need to compare struct value and array value. I need something that is same as NEQ in coldfusion. If anyone can help with this problem please let me know.

1
Is this structFindValue(myStruct[myrow[1]],myrow[2]) what you are trying to do? - rrk
I'm trying to compare value from my structure and value from my array. - espresso_coffee
Try this <cfif structFindValue(myStruct[myrow[1]].code, myrow[2])>. - rrk
That works, thank you! - espresso_coffee

1 Answers

3
votes

You can access the data like this.

<cfif structFindValue(myStruct[myrow[1]].code, myrow[2])>