Counts instances of a specified value in a list. The search is case-sensitive.
The number of instances of value in the list.
List functions, String functions
ListValueCount(list, value [, delimiters ])
<cfquery name = "SearchByDepartment" datasource = "cfsnippets"> SELECT Department FROM Employees </cfquery> <h3>ListValueCount Example</h3> <p>This example uses ListValueCount to count employees in a department. <form action = "listvaluecount.cfm"> <p>Select a department:</p> <select name = "departmentName"> <option value = "Accounting"> Accounting </OPTION> <option value = "Administration"> Administration </OPTION> <option value = "Engineering"> Engineering </OPTION> <option value = "Sales"> Sales </OPTION> </select> <input type = "Submit" name = "Submit" value = "Search Employee List"> </form> <!--- wait to have a string for searching defined ---> <cfif IsDefined("FORM.Submit") and IsDefined("FORM.departmentName")> <cfset myList = ValueList(SearchByDepartment.Department)> <cfset numberInDepartment = ListValueCount(myList, FORM.departmentName)> <cfif numberInDepartment is 0> <h3>There are no employees in <cfoutput>#FORM.departmentName#</cfoutput></h3> <cfelseIf numberInDepartment is 1> <cfoutput> <p>There is only one person in #FORM.departmentName#. </cfoutput> <cfelse> <cfoutput> <p>There are #numberInDepartment# people in #FORM.departmentName#. </cfoutput> </cfif> </cfif>