User Guide
Returning Results to the User 55
Returning Results to the User
When you return your results to the user, you must make sure that your pages
respond to the user’s needs and are appropriate for the type and amount of
information. In particular you must consider the following situations:
• When there are no query results
• When you want to return partial results
If there are no query results
Your code must accommodate the cases where a query does not return any records.
To determine whether a search has retrieved records, use the
RecordCount query
variable. You can use the variable in a conditional logic expression that determines
how to display search results appropriately to users.
For example, to inform the user when no records were found by the GetEmployees
query, insert the following code before displaying the data:
<cfif GetEmployees.RecordCount IS "0">
No records match your search criteria. <BR>
<cfelse>
You mst do the following:
• Prefix RecordCount with the query name.
• Add a procedure after the cfif tag that displays a message to the user.
• Add a procedure after the
cfelse tag to format the returned data.
• Follow the second procedure with a </cfif> tag end to indicate the end of the
conditional code.
To return search results to users:
1 Open the page actionpage.cfm in ColdFusion Studio.
2 Change 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>