About CFML elements
21
Using functions on values
Usually, a function performs an operation on a value, and the value can include the value of a
variable. For example, to format the value of a variable that contains a value in dollars, the code to
write this statement might look like this:
#DollarFormat(price)#
The
DollarFormat
function returns a value as a string and formats that value with two decimal
places, a thousands separator, and a dollar sign. The number signs (#) around the function
instruct ColdFusion to evaluate the content between the number signs and display the value.
Nesting functions
Functions can generate data, as well as act on data. Consider the following example:
#DateFormat(Now(), "mm/dd/yyyy")#
In this example, the
Now()
function generates the date, and then the
DateFormat
function
formats the date.
Variables
Variables let you store data in memory on the server. Variables always have a name and a value.
You can assign a value to a variable, or you can instruct ColdFusion to assign variable values based
on data that it retrieves from a data source, such as a database table.
Naming variables
You must use the following rules for naming ColdFusion variables:
•
Names are case-insensitive (uppercase, lowercase, or mixed case).
•
Names can contain only letters, numbers, and underscore characters.
•
Each name must begin with a letter.
•
Special characters (such as double-quotation marks ("), reserved names (such as functions and
tags), and spaces are not allowed.
Ways to use variables
You can use variables for the following purposes:
•
Store data collected from a form.
•
Store results of a calculation (such as the number of database records returned).
•
Use as input to a function.
Creating variables with the cfset tag
ColdFusion lets you create variables as you need them. You create the variable (name and value)
using the
cfset
tag. This tag has the following syntax:
<cfset variable_name = value>
Summary of Contents for COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION...
Page 1: ...COLDFUSION MX7 Getting Started Building ColdFusion MX Applications...
Page 6: ...6 Contents...
Page 10: ......
Page 14: ...14 Chapter 1 Introducing ColdFusion MX...
Page 38: ...38 Chapter 3 Database Fundamentals...
Page 40: ......
Page 58: ...58 Chapter 5 Lesson 2 Configuring Your Development Environment...
Page 70: ...70 Chapter 6 Lesson 3 Retrieving Data...
Page 84: ...84 Chapter 7 Lesson 4 Building Dynamic Queries...
Page 96: ...96 Chapter 8 Lesson 5 Creating a Trip Detail Page...
Page 102: ...102 Chapter 9 Lesson 6 Creating a Main Application Page...