User Guide
26 Developing Web Applications with ColdFusion
4 #FirstName#, #LastName#, #Salary#, #Contract#<BR>
4 </CFOUTPUT>
</BODY>
</HTML>
3. Save the file as emplist.cfm.
4. View the page in a browser.
A list of employees appears in the browser, with each line displaying one row of
data.
You have created a ColdFusion application page that retrieves and displays data from a
database. At present, the output is raw. You will learn how to format the data in the
next chapter.
Code Review
You now display the results of the query on the page.
Query Output Notes and Considerations
When outputting query results, keep these guidelines in mind:
• Run a CFQUERY before referencing its results using a CFOUTPUT with a
QUERY attribute.
• It’s a good idea to run all queries before all output blocks.
• A query name must exist on the page in order to successfully output its data.
• Surround variable references with pound signs to output their current values to
a page.
• Prefix variables with their variable type — in the case of a query variable, it's the
name of the query.
Code Description
<CFOUTPUT QUERY="EmpList">
Display information retrieved in the
EmpList query
#FirstName#, #LastName#,
#Salary#, #Contract#
Display the value of the FirstName,
LastName, Salary, Contract
fields of the first record
<BR>
Insert a line break (go to the next line
Then, keep displaying the fields
you’ve specified for each record,
followed by a line break, until you run
out of records.
</CFOUTPUT>
End the CFOUTPUT block