Outputting Query Data - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

ColdFusion creates the EmpList data set, but only HTML and text return to the browser.
When you view the page's source, you see only HTML tags and the heading "Employee List."
To display the data set on the page, you must code tags and variables to output the data.
Reviewing the code
The query you just created retrieves data from the CompanyInfo database. The following table
describes the highlighted code and its function:
Code
<cfquery name="EmpList"
datasource="CompanyInfo">
SELECT FirstName, LastName,
Salary, Contract
FROM Employee
</cfquery>

Outputting query data

After you define a query on a page, you can use the
output data from the record set to a page. When you use the
in mind:
ColdFusion loops through all the code contained within the
row in the record set returned from the database.
You must reference specific column names within the
the page.
You can place text, CFML tags, and HTML tags inside or surrounding the
format the data on the page.
Although you do not have to specify the query name when you refer to a query column, you
should use the query name as a prefix for best practices reasons. For example, if you specify the
Emplist query in your
query as Firstname. However, using the query name as a prefix—Emplist.Firstname— is
preferred, and is in the following procedure.
The
tag accepts a variety of optional attributes but, ordinarily, you use the
cfoutput
attribute to define the name of an existing query.
To output query data on your page:
Edit emplist.cfm so that it appears as follows:
1
<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>
Description
Queries the database specified in the CompanyInfo data
source.
Gets information from the FirstName, LastName, Salary, and
Contract fields in the Employee table.
Ends the
cfquery
tag, you can refer to the Firstname column in the Emplist
cfoutput
block.
tag with the
cfoutput
attribute, keep the following
query
cfoutput
block to output the data to
cfoutput

Outputting query data

attribute to
query
block, once for each
block to
cfoutput
query
431

Advertisement

Table of Contents
loading
Need help?

Need help?

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

Questions and answers

This manual is also suitable for:

Coldfusion mx

Table of Contents