Chapter 4: Retrieving and Formatting the Data You Want
35
But when you want to return information about employees that match user search
criteria, you use the SQL WHERE clause with a SQL SELECT statement to compare a
value against a character string field. When the WHERE clause is processed, it filters
the query data based on the results of the comparison.
For example, to return employee data for only employees with the last name of Allaire,
you would build a query that looks like this:
<CFQUERY NAME="GetEmployees" DATASOURCE="CompanyInfo">
SELECT FirstName, LastName, Contract
FROM Employees
4
WHERE LastName = ’Allaire’
</CFQUERY>
However, instead of putting the LastName directly in the SQL WHERE clause, you can
use the text the user entered in the form for comparison:
<CFQUERY NAME="GetEmployees" DATASOURCE="CompanyInfo">
SELECT FirstName, LastName, Salary
FROM Employees
4
WHERE LastName=’#Form.LastName#’
</CFQUERY>
Creating Action Pages
To create an action page for the form:
1.
Create a new application page in Studio.
2.
Enter the following code:
<HTML>
<HEAD>
<TITLE>Retrieving Employee Data Based on Criteia from Form</TITLE>
</HEAD>
<BODY>
<CFQUERY NAME="GetEmployees" DATASOURCE="CompanyInfo">
SELECT FirstName, LastName, Salary
FROM Employees
WHERE LastName=’#Form.LastName#’
</CFQUERY>
<H4>Employee Data Based on Criteria from Form</H4>
<CFOUTPUT query="GetEmployees">
#FirstName#
#LastName#
#Salary#<BR>
</CFOUTPUT>
</BODY>
</HTML>
3.
Save the page as
actionpage.cfm
within the
myapps
directory.
4.
View
formpage.cfm
in your browser.
Summary of Contents for COLDFUSION 4.5-DEVELOPING WEB
Page 1: ...Allaire Corporation Developing Web Applications with ColdFusion ColdFusion 4 5...
Page 14: ...xiv Developing Web Applications with ColdFusion...
Page 26: ...xxvi Developing Web Applications with ColdFusion...
Page 34: ...8 Developing Web Applications with ColdFusion...
Page 70: ...44 Developing Web Applications with ColdFusion...
Page 84: ...58 Developing Web Applications with ColdFusion...
Page 114: ...88 Developing Web Applications with ColdFusion...
Page 148: ...122 Developing Web Applications with ColdFusion...
Page 174: ...148 Developing Web Applications with ColdFusion...
Page 208: ...182 Developing Web Applications with ColdFusion...
Page 244: ...218 Developing Web Applications with ColdFusion...
Page 274: ...248 Developing Web Applications with ColdFusion...
Page 288: ...262 Developing Web Applications with ColdFusion...
Page 300: ...274 Developing Web Applications with ColdFusion...
Page 350: ...324 Developing Web Applications with ColdFusion...
Page 362: ...336 Developing Web Applications with ColdFusion...