Use the CFOUTPUT tag to define the query variable that you want to output to a page . When you use the QUERY attribute:
The CFOUTPUT tag accepts a variety of optional attributes but, most frequently, you will use the QUERY attribute to define the name of an existing query.
Refer to the CFML Language Reference for ColdFusion Express for full CFOUTPUT syntax.
The code below outputs the data contained in the FirstName, LastName, StartDate, and Contract columns of the EmpList query - a query performed earlier on the same page:
<CFOUTPUT QUERY="EmpList"> #FirstName# #LastName# #StartDate# #Salary# #Contract#<BR> </CFOUTPUT>
![]() |
Note: | You will learn how to use an HTML table to format the output Chapter 6, Formatting and Manipulating Data. |
A query name must exist on the page in order to successfully output its data.
![]() |
To output query data on your page: |
EmpList.cfm
in HomeSite.<CFOUTPUT QUERY="EmpList"> </CFOUTPUT>
#FirstName# #LastName# #StartDate# #Salary# #Contract#<BR>
Your page should look like this:
<HTML> <HEAD> <TITLE>Employee List</TITLE> </HEAD> <BODY> <H1>Employee List</H1> <CFQUERY NAME="EmpList" DATASOURCE="HRExpress"> SELECT FirstName,LastName, StartDate, Salary, Contract FROM Employees </CFQUERY> <CFOUTPUT QUERY="EmpList"> #FirstName# #LastName# #StartDate# #Salary# #Contract#<BR> </CFOUTPUT> </BODY> </HTML>
A client list displays in the browser.
Each line displays one row of data.
Click here to see how the page should look at this time.
Click here to see the code behind the scenes.
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.