Adobe COLDFUSION 9 Manual page 719

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Code
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=<cfqueryparam
value="#Form.Department#"
CFSQLType="CF_SQL_VARCHAR">
</cfif>
<cfif Form.LastName IS NOT "">
AND Employee.LastName=<cfqueryparam
value="#Form.LastName#"
CFSQLType="CF_SQL_VARCHAR">
</cfif>
Returning results to the user
When you return your results to the user, ensure that your pages respond to the user's needs and are appropriate for
the type and amount of information. In particular, 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
that determines how to display search results appropriately to users.
Note: For more information on query variables, including
page 410.
For example, to inform the user when no records are 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>
Do the following:
• Prefix
with the query name.
RecordCount
• Add a procedure after the
• Add a procedure after the
• Follow the second procedure with a
Return search results to users
1
Edit the actionpage.cfm page.
2
Change the page so that it appears as follows:
Description
Retrieves the fields listed from the Departmt and Employee tables, joining the
tables based on the Dept_ID field in each table.
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. Use number signs
(#) in the SQL AND statement to identify Form.Department as a ColdFusion
variable, but not in the IsDefined function.
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.
query variable. You can use the variable in a conditional logic expression
RecordCount
RecordCount
tag that displays a message to the user.
cfif
tag to format the returned data.
cfelse
tag end to indicate the end of the conditional code.
</cfif>
Last updated 8/5/2010
, see
"Accessing and Retrieving
714
Data" on

Advertisement

Table of Contents
loading

Table of Contents