MACROMEDIA COLDFUSION 4.5-DEVELOPING WEB Develop Manual page 82

Developing web applications with coldfusion
Table of Contents

Advertisement

56
<TABLE>
<TR>
</TR>
<CFOUTPUT QUERY="GetEmployees">
<TR>
</TR>
</CFOUTPUT>
</TABLE>
</BODY>
</HTML>
3.
Save the page as
4.
Open the file
submit the form.
5.
The results should meet the criteria you specify.
Code Review
The action page
user enters in the form page AskEmp.cfm.
CFML Code
SELECT *
FROM Employees
WHERE 0=0
<CFIF #Form.FirstName# is not "">
AND Employees.FirstName LIKE
'#form.FirstName#%'
</CFIF>
<TH>First Name</TH>
<TH>Last Name</TH>
<TH>Salary</TH>
<TH>Contractor</TH>
<TD>#FirstName#</TD>
<TD>#LastName#</TD>
<TD>#DollarFormat(Salary)#</TD>
<TD>#Contract#</TD>
getemp.cfm
in your browser and enter criteria into any fields, then
askemp.cfm
build a SQL statement dynamically based on what the
getemp.cfm
Developing Web Applications with ColdFusion
.
Description
Get all the records from the Employees
table as long as 0=0.
The WHERE 0=0 clause has no impact on
the query submitted to the database. But
if none of the conditions is true, it ensures
that the WHERE clause does not result in a
SQL syntax error.
If the user entered anything in the
FirstName text box in the form, add "AND
Employees.FirstName LIKE '[what the user
entered in the FirstName text box]%'" to the
SQL statement.

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION 4.5-DEVELOPING WEB and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Coldfusion 4.5

Table of Contents