Reputation: 329
I ran into another problem. I'm trying to figure out how to only have 1 record set of the newResult
variable instead of it displaying many times?
qrykeylist is from the database. and newArray is not from database but constructed from the array.
I needed to loop over both in order to get all the results. I managed to get them how I wanted but I cannot figure out how to make it only show 1 record result set from both of the looped over results from both the query and array.
I googled around and some have told me when having nested loops put both into an array of structures but how can I do that if both of these needs to be looped over? In addition, I cannot write this outside of inner loop because I need to use BOTH variables to output the results.
Here is my code:
<cfoutput>
<cfloop index="i" from="1" to="#ArrayLen(newArray)#">
<cfloop query="qrykeylist">
<strong><br>#ITEM[i]#</strong>
<cfset newResult = SHOULDBE - newArray[i]>
<cfif newArray[i] GT SHOULDBE>
<br>Missing Keys #newResult#
<cfelseif newArray[i] LT SHOULDBE>
<br>Extra Keys #newResult#
<cfelseif newArray[i] EQ SHOULDBE>
<br>No Missing Keys
</cfif>
<cfbreak>
</cfloop>
</cfloop>
Here is the results of the image the ones that arent in boxes are being duplicated most likely by the loop?
Upvotes: 1
Views: 216
Reputation: 11120
This is really a comment, but it way too long. It looks like you have
<cfoutput query="qrykeylist">
<cfloop index="i" from="1" to="#ArrayLen(newArray)#">
<cfloop query="qrykeylist">
This is nested 3 levels deep. I don't think you want loop over qrykeylist
twice.
**On a different note
<cfif #newArray[i]# GT #SHOULDBE#>
could be written as:
<cfif newArray[i] GT SHOULDBE>
You only wrap variables in ## when displaying the values.
Upvotes: 1