home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 April / APC443.iso / features / grpware / coldfus / coldfusi.exe / data1.cab / Documentation / snippets / cfif.cfm < prev    next >
Encoding:
Text File  |  1998-10-08  |  2.7 KB  |  82 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. <BODY>
  18. <H3>CFIF Example</H3>
  19.  
  20. <P>CFIF gives us the ability to perform conditional logic
  21. based on a condition or set of conditions.
  22. <P>For example, we can output the list of Centers from the
  23. snippets datasource by group and only display them <B>IF</B>
  24. City = San Diego.
  25. <hr>
  26. <!--- use CFIF to test a condition when outputting
  27. a query --->
  28. <P>The following are centers in San Diego:
  29.  
  30. <CFOUTPUT QUERY="getCenters" >
  31. <CFIF #Trim(City)# is "San Diego">
  32.     <BR><B>Name/Address:</B>#Name#, #Address1#, #City#, #State#
  33.     <BR><B>Contact:</B> #Contact#<BR>
  34. </CFIF>
  35. </CFOUTPUT>
  36. <HR>
  37. <P>If we would like more than one condition to be the case,
  38. we can ask for a list of the centers in San Diego <B>OR</B>
  39. Santa Ana.  If the center does not follow this condition, we
  40. can use CFELSE to show only the names and cities of the
  41. other centers.
  42. <P>Notice how a nested CFIF is used to specify
  43. the location of the featured site (Santa Ana or San Diego).
  44. <!--- use CFIF to specify a conditional choice for multiple
  45. options; also note the nested CFIF --->
  46.  
  47. <P>Complete information is shown for centers in San Diego
  48. or Santa Ana.  All other centers are listed in italics:
  49.  
  50. <CFOUTPUT QUERY="getCenters">
  51. <CFIF #Trim(City)# is "San Diego" OR #Trim(City)# is "Santa Ana">
  52.     <H4>Featured Center in <CFIF #Trim(City)# is "San Diego">San Diego<CFELSE>Santa Ana</CFIF></H4>
  53.     <B>Name/Address:</B>#Name#, #Address1#, #City#, #State#
  54.     <BR><B>Contact:</B> #Contact#<BR>
  55. <CFELSE>
  56.     <BR><I>#Name#, #City#</I>
  57. </CFIF>
  58. </CFOUTPUT>
  59. <HR>
  60. <P>Finally, we can use CFELSEIF to cycle through a number
  61. of conditions and produce varying output.  Note that you
  62. can use CFCASE and CFSWITCH for a more elegant representation
  63. of this behavior.
  64.  
  65. <P>
  66. <!--- use CFIF in conjunction with CFELSEIF to specify
  67. more than one branch in a conditional situation --->
  68. <CFOUTPUT QUERY="getCenters">
  69. <CFIF #Trim(City)# is "San Diego" OR #Trim(City)# is "Santa Ana">
  70.     <BR><I>#Name#, #City#</I> (this one is in <CFIF #Trim(City)# is "San Diego">San Diego<CFELSE>Santa Ana</CFIF>)
  71. <CFELSEIF #Trim(City)# is "San Francisco">
  72.     <BR><I>#Name#, #City#</I> (this one is in San Francisco)
  73. <CFELSEIF #Trim(City)# is "Suisun">
  74.     <BR><I>#Name#, #City#</I> (this one is in Suisun)
  75. <CFELSE>    
  76.     <BR><I>#Name#</I> <B>Not in a city we track</B>
  77. </CFIF>
  78. </CFOUTPUT>
  79.  
  80. </BODY>
  81. </HTML>       
  82.