ListValueCount(list, value [, delimiters ])

Description

Returns the number of instances of a specified value in a list. The search is case-sensitive.

Category

List functions

See also

ListValueCountNoCase

Parameters

Parameter
Description
list
A list or the name of a list to search.
value
The string or number that the function is to find and count.
delimiter
Optional. The character(s) used to delimit elements in the list. The default is a comma.

Example

<!--- This example uses ListValueCount to find the number 
of employees in a department --->
<html>
<head>
<title>ListValueCount Example</title>
</head>

<body bgcolor = "#FFFFD5">

<cfquery name = "SearchByDepartment" datasource = "cfsnippets">
SELECT     Department
FROM     Employees
</cfquery>

<H3>ListValueCount Example</H3>
<P>This example uses ListValueCount to see how many employees 
are in a department.

<form action = "listvaluecount.cfm" method = "POST">
<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>

</body>
</html>