• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 584
  • Last Modified:

Coldfusion ArrayLen() Problem

I have an array of a structure from which I am already successfully outputting the correct number of results (where Arr_TotalResults[i].SOURCE IS "Gemini", which is outputting 5 rows because only 5 elements EQ Gemini). I now need to get the array length MINUS those which do not have a structure key SOURCE IS "Gemini". I thought the code below would do this because it is already working on the output, however, it's giving me the full length of the array (which is 11) and still including those which do not match 'Gemini'. Please can someone tell me what I'm doing wrong here??

Many thanks,
Michelle


<cfloop from="1" to="#arrayLen(Arr_TotalResults)#" index="i">
 <cfif Arr_TotalResults[i].SOURCE IS "Gemini">
  <cfset js_numBoth=arrayLen(Arr_TotalResults)>
 </cfif>
</cfloop>

<cfoutput>
 #js_numBoth#
</cfoutput>

0
mjacobs2929
Asked:
mjacobs2929
1 Solution
 
hartCommented:
just do this

<cfset nGeminiCtr = 0>
<cfloop from="1" to="#arrayLen(Arr_TotalResults)#" index="i">
   <cfif Arr_TotalResults[i].SOURCE IS "Gemini">
     <cfset nGeminiCtr = IncrementValue(nGeminiCtr)>
   </cfif>
</cfloop>

Now

<cfoutput>
For Gemini Total Count  EQ #nGeminiCtr#<br>
For The total Array Length - #ArrayLen(TotalResults)#<br>
For The count with out Gemini - #Evaluate(ArrayLen(TotalResults)-nGeminiCtr)#<br>
</cfoutput>

Regards
hart
0
 
mjacobs2929Author Commented:
Brilliant!
Thanks so much for the speedy response!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now