User Guide
Working with Queries and Data 53
The following action page allows users to search for employees by department, last
name, or both.
To build a more flexible search interface:
1 Open the page actionpage.cfm in ColdFusion Studio.
2 Modify the page so that it appears as follows:
<html>
<head>
<title>Retrieving Employee Data Based on Criteia from Form</title>
</head>
<body>
<cfquery name="GetEmployees" datasource="CompanyInfo">
SELECT Departmt.Dept_Name,
Employee.FirstName,
Employee.LastName,
Employee.StartDate,
Employee.Salary
FROM Departmt, Employee
WHERE Departmt.Dept_ID = Employee.Dept_ID
<cfif IsDefined("FORM.Department")>
AND Departmt.Dept_Name = ’#Form.Department#’
</cfif>
<cfif Form.LastName IS NOT "">
AND Employee.LastName = ’#Form.LastName#’
</cfif>
</cfquery>
<h4>Employee Data Based on Criteria from Form</h4>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Salary</th>
</tr>
<cfoutput query="GetEmployees">
<tr>
<td>#FirstName#</td>
<td>#LastName#</td>
<td>#Salary#</td>
</tr>
</cfoutput>
</table>
</body>
</html>
3 Save the file.
4 View formpage.cfm in your browser.
5 Select a department, optionally enter a last name, and submit the form.