MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual page 119

Table of Contents

Advertisement

Dynamic SQL
3
4
5
Reviewing the code
The action page
user enters in the form page AskEmp.cfm. The following table describes the
highlighted code and its function:
CFML Code
SELECT *
<cfif #Form.FirstName# is not "">
</cfif>
<cfif #Form.LastName# is not "">
</cfif>
<cfif #Form.Salary# is not "">
</cfif>
<td>#FirstName#</td>
<td>#LastName#</td>
<td>#DollarFormat(Salary)#</td>
<td>#Contract#</td>
</tr>
</cfoutput>
</table>
</body>
</html>
Save the page as
getemp.cfm
Open the file
askemp.cfm
submit the form.
Verify that the results meet the criteria you specify.
getemp.cfm
FROM Employee
WHERE
Employee.FirstName LIKE
'#form.FirstName#%' AND
Employee.LastName LIKE
'#form.LastName#%' AND
Employee.Salary >=
#form.Salary# AND
.
in your browser and enter criteria into any fields, then
builds a SQL statement dynamically based on what the
Description
Get the records from the Employee table
according to the following conditions.
If the user entered anything in the
FirstName text box in the form, add "AND
Employee.FirstName LIKE '[what the user
entered in the FirstName text box]%'" to the
SQL statement. You can use the FirstName
variable without ensuring its existence
because text boxes pass an empty string if
you do not enter text.
If the user entered anything in the
LastName text box in the form, add "AND
Employee.LastName LIKE '[what the user
entered in the LastName text box]%'" to the
SQL statement.
If the user entered anything in the Salary
text box in the form, add "AND
Employee.Salary >= [what the user entered
in the Salary text box]" to the SQL
statement.
99

Advertisement

Table of Contents
loading
Need help?

Need help?

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

Questions and answers

This manual is also suitable for:

Coldfusion 5

Table of Contents