Outputting Query Data - MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual

Table of Contents

Advertisement

30

Outputting Query Data

After you define a query on a page, you can use the
attribute to specify the query object that contains the data you want to output to a
page. When you use the
The
query
To output query data on your page:
1
2
3
4
You 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.
Reviewing the code
ColdFusion loops over all the code contained within the
each row returned from a database.
You must reference specific column names within the
the data to the page.
You can place text, CFML tags, and HTML tags inside or surrounding the
block to format the data on the page.
cfoutput
You do not have to specify the query object name when you refer to a query
column. For example, if you specify the Emplist query in your
can refer to the Firstname column in the Emplist query as either
Emplist.Firstname or just Firstname.
tag accepts a variety of optional attributes but, ordinarily, you use the
cfoutput
attribute to define the name of an existing query.
Return to
empList.cfm
Edit the file so that it appears as follows:
<html>
<head>
<title>Employee List</title>
</head>
<body>
<h1>Employee List</h1>
<cfquery name="EmpList" datasource="CompanyInfo">
SELECT FirstName, LastName, Salary, Contract
FROM Employee
</cfquery>
<cfoutput query="EmpList">
#FirstName#, #LastName#, #Salary#, #Contract#<br>
</cfoutput>
</body>
</html>
Save the file as emplist.cfm.
View the page in a browser.
A list of employees appears in the browser, with each line displaying one row of
data.
attribute:
query
in ColdFusion Studio.
Chapter 3 Querying a Database
tag with the
cfoutput
block, once for
cfoutput
block to output
cfoutput
cfoutput
query
tag, you

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 5

Table of Contents