home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / cfif.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  2.8 KB  |  84 lines

  1. <!--- This example shows the interaction of CFIF, CFELSE,
  2. and CFELSEIF --->
  3.  
  4. <!--- first, perform a query to get some data --->
  5. <CFQUERY NAME="getCenters" DATASOURCE="cfsnippets">
  6. SELECT      Center_ID, Name, Address1, Address2, 
  7.             City, State, Country, PostalCode, Phone, Contact
  8. FROM        Centers
  9. ORDER by City, State, Name
  10. </CFQUERY>
  11.  
  12. <HTML>
  13. <HEAD>
  14. <TITLE>CFIF Example</TITLE>
  15. </HEAD>
  16.  
  17. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  18. <BODY  bgcolor="#FFFFD5">
  19.  
  20. <H3>CFIF Example</H3>
  21.  
  22. <P>CFIF gives us the ability to perform conditional logic
  23. based on a condition or set of conditions.
  24. <P>For example, we can output the list of Centers from the
  25. snippets datasource by group and only display them <B>IF</B>
  26. City = San Diego.
  27. <hr>
  28. <!--- use CFIF to test a condition when outputting
  29. a query --->
  30. <P>The following are centers in San Diego:
  31.  
  32. <CFOUTPUT QUERY="getCenters" >
  33. <CFIF #Trim(City)# is "San Diego">
  34.     <BR><B>Name/Address:</B>#Name#, #Address1#, #City#, #State#
  35.     <BR><B>Contact:</B> #Contact#<BR>
  36. </CFIF>
  37. </CFOUTPUT>
  38. <HR>
  39. <P>If we would like more than one condition to be the case,
  40. we can ask for a list of the centers in San Diego <B>OR</B>
  41. Santa Ana.  If the center does not follow this condition, we
  42. can use CFELSE to show only the names and cities of the
  43. other centers.
  44. <P>Notice how a nested CFIF is used to specify
  45. the location of the featured site (Santa Ana or San Diego).
  46. <!--- use CFIF to specify a conditional choice for multiple
  47. options; also note the nested CFIF --->
  48.  
  49. <P>Complete information is shown for centers in San Diego
  50. or Santa Ana.  All other centers are listed in italics:
  51.  
  52. <CFOUTPUT QUERY="getCenters">
  53. <CFIF Trim(City) is "San Diego" OR Trim(City) is "Santa Ana">
  54.     <H4>Featured Center in <CFIF Trim(City) is "San Diego">San Diego<CFELSE>Santa Ana</CFIF></H4>
  55.     <B>Name/Address:</B>#Name#, #Address1#, #City#, #State#
  56.     <BR><B>Contact:</B> #Contact#<BR>
  57. <CFELSE>
  58.     <BR><I>#Name#, #City#</I>
  59. </CFIF>
  60. </CFOUTPUT>
  61. <HR>
  62. <P>Finally, we can use CFELSEIF to cycle through a number
  63. of conditions and produce varying output.  Note that you
  64. can use CFCASE and CFSWITCH for a more elegant representation
  65. of this behavior.
  66.  
  67. <P>
  68. <!--- use CFIF in conjunction with CFELSEIF to specify
  69. more than one branch in a conditional situation --->
  70. <CFOUTPUT QUERY="getCenters">
  71. <CFIF Trim(City) is "San Diego" OR Trim(City) is "Santa Ana">
  72.     <BR><I>#Name#, #City#</I> (this one is in <CFIF Trim(City) is "San Diego">San Diego<CFELSE>Santa Ana</CFIF>)
  73. <CFELSEIF Trim(City) is "San Francisco">
  74.     <BR><I>#Name#, #City#</I> (this one is in San Francisco)
  75. <CFELSEIF Trim(City) is "Suisun">
  76.     <BR><I>#Name#, #City#</I> (this one is in Suisun)
  77. <CFELSE>    
  78.     <BR><I>#Name#</I> <B>Not in a city we track</B>
  79. </CFIF>
  80. </CFOUTPUT>
  81.  
  82. </BODY>
  83. </HTML>       
  84.