Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 418

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Accessing and Using Data
Reviewing the code
The query you just created retrieves data from the cfdocexamples database. The following table describes the
highlighted code and its function:
Code
<cfquery name="EmpList" datasource="cfdocexamples">
SELECT FirstName, LastName, Salary, Contract
FROM Employee
</cfquery>
Outputting query data
After you define a query, you can use the
When you use the
attribute, keep in mind the following:
query
• ColdFusion loops through all the code contained within the
returned from the database.
• Reference specific column names within the
• You can place text, CFML tags, and HTML tags inside or surrounding the
the page.
• Although you do not have to specify the query name when you refer to a query column, use the query name as a
prefix for best practices reasons. For example, if you specify the Emplist query in your
to the Firstname column in the Emplist 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
name of an existing query.
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="cfdocexamples">
SELECT FirstName, LastName, Salary, Contract
FROM Employee
</cfquery>
<cfoutput query="EmpList">
#EmpList.FirstName#, #EmpList.LastName#, #EmpList.Salary#, #EmpList.Contract#<br>
</cfoutput>
</body>
</html>
Save the file and view it in your web browser:
2
A list of employees appears in the browser, with each line displaying one row of data.
Note: If necessary, refresh your browser to see your changes.
Description
Queries the database specified in the cfdocexamples data source.
Gets information from the FirstName, LastName, Salary, and Contract
fields in the Employee table.
Ends the
cfquery
tag with the
cfoutput
query
cfoutput
block to output the data to the page.
cfoutput
Last updated 1/20/2012
block.
attribute to output data from the recordset.
block, once for each row in the recordset
block to format the data on
cfoutput
tag, you can refer
cfoutput
attribute to define the
query
413

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents