User Guide
Outputting Query Data 31
You now display the results of the query on the page. The following table describes
the code and its function:
Query output notes and considerations
When outputting query results, keep the following guidelines in mind:
• A
cfquery must precede the cfoutput that references its results. Both must be on
the same page (unless you use the
cfinclude tag).
• It is a good idea to run all queries before all output blocks.
• To output data from all the records of a query, specify the query name by using
the query attribute in the cfoutput tag.
• Columns must exist and be retrieved to the application in order to output their
values.
• Inside a
cfoutput block that uses a cfquery attribute you can optionally prefix
the query variables with the name of the query, for example
Emplist.FirstName.
• As with other attributes, surround the query attribute value with double quotes
(").
• As with any variables that you reference for output, surround column names with
pound signs (#) to tell ColdFusion to output the column’s current values.
• Add a
<br> tag to the end of the variable references so that ColdFusion starts a
new line for each row that is returned from the query.
Code Description
<cfoutput query="EmpList">
Display information retrieved in the EmpList
query. Display information for each record in
the query, until you run out of records.
#FirstName#, #LastName#,
#Salary#, #Contract#
Display the value of the FirstName,
LastName, Salary, Contract
fields of each
record, separated by commas and spaces.
<br>
Insert a line break (go to the next line) after
each record.
</cfoutput>
End the cfoutput block.