198
CFML Language Reference
Example
<!--- This example shows how to use CFSET --->
<CFQUERY NAME="GetMessages" DATASOURCE="cfsnippets">
SELECT *
FROM Messages
</CFQUERY>
<HTML>
<HEAD>
<TITLE>
CFSET Example
</TITLE>
</HEAD>
<BODY bgcolor=silver>
<H3>CFSET Example</H3>
<P>CFSET allows you to set and reassign values to local or
global variables within a CF template.
<CFSET NumRecords = GetMessages.RecordCount>
<P>For example, the variable NumRecords has been declared on
this template to hold the amount of records returned from
our query (<CFOUTPUT>#NumRecords#</CFOUTPUT>).
<P>In addition, CFSET can be used to pass variables from other
pages, such as this example which takes the url parameter
Test from this link
(<a href="cfset.cfm?test=<CFOUTPUT>#URLEncodedFormat("
hey, you, get off of my cloud")#</CFOUTPUT>">click here</A>) to display
a message:
<P><CFIF IsDefined ("url.test") is "True">
<CFOUTPUT><B><I>#url.test#</I></B></CFOUTPUT>
<CFELSE>
<H3>The variable url.test has not been passed from
another page.</H3>
</CFIF>
<P>Finally, CFSET can also be used to collect environmental
variables, such as the time, the IP address of the user, or any
other function or expression possible in ColdFusion.
<CFSET the_date =
#DateFormat(Now())# & " " & #TimeFormat(Now())#>
<CFSET user_ip = CGI.REMOTE_ADDR>
<CFSET complex_expr = (23 MOD 12) * 3>
<CFSET str_example = Reverse(Left(GetMessages.body, 35))>
...
Summary of Contents for COLDFUSION 4.5-CFML LANGUAGE
Page 1: ...Allaire Corporation CFML Language Reference ColdFusion 4 5...
Page 207: ...Chapter 1 ColdFusion Tags 183 CFCATCH CFTRY BODY HTML...
Page 224: ...200 CFMLLanguageReference CFOUTPUT P Text within CFOUTPUT is always shown CFOUTPUT BODY HTML...
Page 336: ...312 CFMLLanguageReference CFIF BODY HTML...
Page 404: ...380 CFMLLanguageReference DE It is morning CFOUTPUT P BODY HTML...
Page 413: ...Chapter 2 ColdFusion Functions 389 Customer BalanceDue BR CFOUTPUT CFIF BODY HTML...
Page 483: ...Chapter 2 ColdFusion Functions 459 CFOUTPUT CFLOOP BODY HTML...
Page 584: ...560 CFMLLanguageReference...
Page 594: ...570 CFMLLanguageReference...