User Guide

Table Of Contents
Returning results to the user 621
Reviewing the code
The following table describes the highlighted code and its function:
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 return partial results
Handling no query results
Your code must accommodate the cases in which 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.
Note: For more information on query variables, including RecordCount, see Chapter 20, “Accessing
and Retrieving Data,” on page 465.
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>
Code Description
SELECT Departmt.Dept_Name,
Employee.FirstName,
Employee.LastName,
Employee.StartDate,
Employee.Salary
FROM Departmt, Employee
WHERE Departmt.Dept_ID =
Employee.Dept_ID
Retrieves the fields listed from the Departmt and
Employee tables, joining the tables based on the
Dept_ID field in each table.
<cfif IsDefined("FORM.Department")>
AND Departmt.Dept_Name =
<cfqueryparam
value="#Form.Department#"
CFSQLType="CF_SQL_VARCHAR">
</cfif>
If the user specified a department on the form, only
retrieves records where the department name is the
same as the one that the user specified. You must use
number signs (#) in the SQL AND statement to
identify Form.Department as a ColdFusion variable,
but not in the
IsDefined function.
<cfif Form.LastName IS NOT "">
AND Employee.LastName = <cfqueryparam
value="#Form.LastName#"
CFSQLType="CF_SQL_VARCHAR">
</cfif>
If the user specified a last name in the form, only
retrieves the records in which the last name is the
same as the one that the user entered in the form.