home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Documentation / snippets / listvaluecount.cfm < prev    next >
Encoding:
Text File  |  1999-04-12  |  1.5 KB  |  59 lines

  1. <!--- This example uses ListValueCount to see how many 
  2.       employees are in a department --->
  3. <HTML>
  4. <HEAD>
  5. <TITLE>ListValueCount Example</TITLE>
  6. </HEAD>
  7.  
  8. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  9.  
  10. <BODY  bgcolor="#FFFFD5">
  11.  
  12. <CFQUERY Name="SearchByDepartment" DATASOURCE="cfsnippets">
  13. SELECT     Department
  14. FROM     Employees
  15. </CFQUERY>
  16.  
  17. <H3>ListValueCount Example</H3>
  18. <P>This example uses ListValueCount to see how many employees 
  19. are in a department.
  20.  
  21. <FORM ACTION="listvaluecount.cfm" METHOD="POST">
  22. <P>Select a department:</P>
  23.     <SELECT NAME="departmentName">
  24.             <OPTION VALUE="Accounting">
  25.                 Accounting
  26.             </OPTION>    
  27.             <OPTION VALUE="Administration">
  28.                 Administration
  29.             </OPTION>    
  30.             <OPTION VALUE="Engineering">
  31.                 Engineering
  32.             </OPTION>    
  33.             <OPTION VALUE="Sales">
  34.                 Sales
  35.             </OPTION>                            
  36.     </SELECT>
  37. <INPUT TYPE="Submit" NAME="Submit" VALUE="Search Employee List">
  38. </FORM>
  39.  
  40. <!--- wait to have a string for searching defined --->
  41. <CFIF IsDefined("form.Submit") and IsDefined("form.departmentName")>
  42.     <CFSET myList = ValueList(SearchByDepartment.Department)>
  43.     <CFSET numberInDepartment = ListValueCount(myList, form.departmentName)> 
  44.          
  45.     <CFIF numberInDepartment is 0>
  46.         <H3>There are no employees in <CFOUTPUT>#form.departmentName#</CFOUTPUT></H3>
  47.     <CFELSEIF numberInDepartment is 1>
  48.         <CFOUTPUT>
  49.         <P>There is only one person in #form.departmentName#.
  50.         </CFOUTPUT>
  51.     <CFELSE>
  52.         <CFOUTPUT>
  53.         <P>There are #numberInDepartment# people in #form.departmentName#.
  54.         </CFOUTPUT>
  55.     </CFIF>
  56. </CFIF>
  57.  
  58. </BODY>
  59. </HTML>