User Guide
56 Developing Web Applications with ColdFusion
<TABLE>
<TR>
<TH>First Name</TH>
<TH>Last Name</TH>
<TH>Salary</TH>
<TH>Contractor</TH>
</TR>
<CFOUTPUT QUERY="GetEmployees">
<TR>
<TD>#FirstName#</TD>
<TD>#LastName#</TD>
<TD>#DollarFormat(Salary)#</TD>
<TD>#Contract#</TD>
</TR>
</CFOUTPUT>
</TABLE>
</BODY>
</HTML>
3. Save the page as getemp.cfm.
4. Open the file
askemp.cfm in your browser and enter criteria into any fields, then
submit the form.
5. The results should meet the criteria you specify.
Code Review
The action page getemp.cfm build a SQL statement dynamically based on what the
user enters in the form page AskEmp.cfm.
CFML Code Description
SELECT *
FROM Employees
WHERE 0=0
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.
<CFIF #Form.FirstName# is not "">
AND Employees.FirstName LIKE
’#form.FirstName#%’
</CFIF>
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.