Query output notes and considerations
When outputting query results, keep the following guidelines in mind:
•
A
must precede the
cfquery
page (unless you use the
cfinclude tag" on page
•
It is a good idea to place queries at the top of the page, to simplify testing and debugging.
However, some queries might not execute if certain conditions are not met.
•
To output data from all the records of a query, specify the query name by using the
attribute in the
•
Columns must exist and be retrieved to the application to output their values.
•
Inside a
cfoutput
the name of the query; for example,
•
As with other attributes, surround the
•
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
tag to the end of the variable references so that ColdFusion starts a new line for
<br>
each row that the query returns.
Getting information about query results
Each time you query a database with the
query variables; together these comprise the query object. The following table describes the query
variables, which are sometimes referred to as query properties:
Variable
RecordCount
ColumnList
CurrentRow
In your CFML code, you can use these variables as if they were columns in a database table.
To output the query record count 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>
<cfoutput query="EmpList">
#
FirstName#, #
EmpList.
#
Contract#<br>
EmpList.
</cfoutput>
<br>
cfoutput
tag; for more information, see
cfinclude
164).
tag.
cfoutput
block that uses a
cfquery
Emplist.FirstName
Description
The total number of records returned by the query.
A comma-delimited list of the query columns, in alphabetical order.
The current row of the query being processed by
EmpList.
that references its results. Both must be on the same
attribute, you can prefix the query variables with
.
attribute value with double quotes (").
query
tag, you get the data (the record set) and the
cfquery
LastName#, #
EmpList.
Getting information about query results
"Including pages with the
.
cfoutput
Salary#,
query
433
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