Chapter 3: Querying a Database
27
•
When outputting the data itself, you define the variable name using the QUERY
attribute.
•
When outputting query properties variables, don’t use the QUERY attribute;
instead, prefix the variable reference with the name of the query, for example,
EmpList.RecordCount
.
•
Columns must exist and be retrieved to the application in order to output their
values.
•
As with other attributes, surround the QUERY 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 will
start a new line for each row that is returned from the query.
Getting Information About Query Results
Each time you query a database with the CFQUERY tag, you get not only the data itself,
but also query properties, as described in the following table::
To output query data on your page:
1.
Return to
emplist.cfm
in Studio.
2.
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 Employees
</CFQUERY>
<CFOUTPUT QUERY="EmpList">
#FirstName#, #LastName#, #Salary#, #Contract#<BR>
</CFOUTPUT>
Query Properties
Property
Description
RecordCount
The total number of records returned by the query.
ColumnList
Returns a comma-delimited list of the query columns.
CurrentRow
The current row of the query being processed by CFOUTPUT.
Summary of Contents for COLDFUSION 4.5-DEVELOPING WEB
Page 1: ...Allaire Corporation Developing Web Applications with ColdFusion ColdFusion 4 5...
Page 14: ...xiv Developing Web Applications with ColdFusion...
Page 26: ...xxvi Developing Web Applications with ColdFusion...
Page 34: ...8 Developing Web Applications with ColdFusion...
Page 70: ...44 Developing Web Applications with ColdFusion...
Page 84: ...58 Developing Web Applications with ColdFusion...
Page 114: ...88 Developing Web Applications with ColdFusion...
Page 148: ...122 Developing Web Applications with ColdFusion...
Page 174: ...148 Developing Web Applications with ColdFusion...
Page 208: ...182 Developing Web Applications with ColdFusion...
Page 244: ...218 Developing Web Applications with ColdFusion...
Page 274: ...248 Developing Web Applications with ColdFusion...
Page 288: ...262 Developing Web Applications with ColdFusion...
Page 300: ...274 Developing Web Applications with ColdFusion...
Page 350: ...324 Developing Web Applications with ColdFusion...
Page 362: ...336 Developing Web Applications with ColdFusion...