Chapter 4: Retrieving and Formatting the Data You Want
41
<CFIF Form.LastName IS NOT "">
AND Employees.LastName = ’Form.LastName’
</CFIF>
</CFQUERY>
Code Review
To build a flexible search interface:
1.
Return to
actionpage.cfm
in Studio.
2.
Modify the page so that it appears as follows:
<HTML>
<HEAD>
<TITLE>Retrieving Employee Data Based on Criteria from Form</TITLE>
</HEAD>
<BODY>
<CFQUERY NAME="GetEmployees" DATASOURCE="CompanyInfo">
4
SELECT Departments.Department.Name,
4
Employees.FirstName,
4
Employees.LastName,
4
Employees.StartDate,
4
Employees.Salary
4
FROM Departments, Employees
4
WHERE Departments.Department_ID = Employees.Department_ID
4
<CFIF Form.Department_Name IS NOT "">
4
AND Departments.Department_Name = ’Form.Department_Name’
4
</CFQUERY>
<H4>Employee Data Based on Criteia from Form</H4>
<TABLE>
<TR>
<TH>First Name</TH>
<TH>Last Name</TH>
<TH>Salary</TH>
Code
Description
SELECT Departments.Department.Name,
Employees.FirstName,
Employees.LastName,
Employees.StartDate,
Employees.Salary
FROM Departments, Employees
WHERE 1=1
Retrieve the fields listed from the Departments
and Employees tables, joining the tables based
on the Department_ID field in each table.
<CFIF Form.LastName IS NOT "">
AND Employees.LastName = ’Form.LastName’
</CFIF>
But if the user specified a last name in the form,
only retrieve the records where the last name is
the same as the one the user entered in the
form.
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...