MACROMEDIA COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX Getting Started page 70

Building coldfusion mx applications
Table of Contents

Advertisement

When the user enters the search criteria on the Trip Search form and clicks the Search button, the
form fields are then posted to the Trip Search Results page. The posted field values compose the
WHERE clause in the SQL SELECT statement. The following example lists the WHERE clauses
that can be generated depending on the criteria set on the search page:
WHERE tripLocation = 'China'
WHERE tripLocation Like 'C%'
WHERE tripLocation = 'China'
AND departureDate > 1/1/2001
AND price < 1500
In the previous example, the SQL AND operator joins the search condition clauses. To simplify
the trip search example, you will use the SQL AND operator to combine all the search condition
clauses. A more sophisticated search criteria page might present the user a choice of using AND or
OR to connect one search criterion with the others.
The search action page uses a SQL SELECT statement to display an HTML table with the results
of the user query using the
Building the WHERE Clause with the cfif and cfset
The WHERE clause in a SQL SELECT is a string. You use the CFML
conditionally build the WHERE clause depending on values passed to the search action page.
The
statement creates a new variable or changes the value of an existing variable. For
cfset
example, to create a variable named
statement:
<cfset color = "red">
The
tag instructs the program to branch to different parts of the code depending on
cfif
whether a test evaluates to True or False. For example, to have some code execute if the
variable is equal to
<cfif color EQ "red">
... statements for color red
<cfelse>
... statements for other than red
</cfif>
Building a SQL WHERE clause in code is largely an exercise in string concatenation. The
operator combines two strings in ColdFusion. For example, the following code snippet:
<cfset FirstName = "Dylan">
<cfset LastName = "Smith">
<cfset FullName = FirstName & " " & LastName>
<cfoutput>My name is #FullName#.</cfoutput>
results in the following text:
My name is Dylan Smith.
70
Chapter 6: Lesson 2: Writing Your First ColdFusion Application
block.
cfoutput
color
and other code execute if it is not, you use the following pseudocode:
red,
and initialize its value to
and
tags to
cfset
cfif
, you use the following
red
color
&

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Coldfusion mx

Table of Contents