home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 April / APC443.iso / features / grpware / coldfus / coldfusi.exe / data1.cab / Documentation / snippets / cfset.cfm < prev    next >
Encoding:
Text File  |  1998-10-08  |  1.8 KB  |  64 lines

  1. <!--- This example shows how to use CFSET --->
  2.  
  3. <CFQUERY NAME="GetMessages" DATASOURCE="cfsnippets">
  4. SELECT   *
  5. FROM     Messages
  6. </CFQUERY>
  7.  
  8. <HTML>
  9.  
  10. <HEAD>
  11. <TITLE>
  12. CFSET Example
  13. </TITLE>
  14. </HEAD>
  15.  
  16. <BODY bgcolor=silver>
  17.  
  18. <H3>CFSET Example</H3>
  19.  
  20. <P>CFSET allows you to set and reassign values to local or
  21. global variables within a CF template.
  22.  
  23. <CFSET NumRecords = GetMessages.RecordCount>
  24. <P>For example, the variable NumRecords has been declared on
  25. this template to hold the amount of records returned from
  26. our query (<CFOUTPUT>#NumRecords#</CFOUTPUT>).
  27.  
  28. <P>In addition, CFSET can be used to pass variables from other 
  29. pages, such as this example which takes the url parameter
  30. Test from this link (<a href="cfset.cfm?test=<CFOUTPUT>#URLEncodedFormat("
  31. hey, you, get off of my cloud")#</CFOUTPUT>">click here</A>) to display 
  32. a message: 
  33. <P><CFIF IsDefined ("url.test") is "True">
  34.     <CFOUTPUT><B><I>#url.test#</I></B></CFOUTPUT>
  35. <CFELSE>
  36.     <H3>The variable url.test has not been passed from
  37.     another page.</H3>
  38. </CFIF>
  39.  
  40. <P>Finally, CFSET can also be used to collect environmental
  41. variables, such as the time, the ip of the user, or any
  42. other function or expression possible in Cold Fusion.
  43.  
  44. <CFSET the_date = #DateFormat("#Now()#")# & " " & #TimeFormat("#Now()#")#>
  45. <CFSET user_ip = CGI.REMOTE_ADDR>
  46. <CFSET complex_expr = (23 MOD 12) * 3>
  47. <CFSET str_example = Reverse("#Left("#GetMessages.body#", 35)#")>
  48.  
  49.  
  50. <CFOUTPUT>
  51. <UL>
  52.     <LI>The date: #the_date#
  53.     <LI>User IP Address: #user_ip#
  54.     <LI>Complex Expression ((23 MOD 12) * 3): #complex_expr#
  55.     <LI>String Manipulation (the first 35 characters of
  56.     the body of the first message in our query)
  57.     <BR><B>Reversed</B> :#str_example#
  58.     <BR><B>Normal</B>: #Reverse("#str_example#")#
  59. </UL>
  60. </CFOUTPUT>
  61. </BODY>
  62.  
  63. </HTML>       
  64.