Query Notes And Considerations; Outputting Query Data - MACROMEDIA COLDFUSION 4.5-DEVELOPING WEB Develop Manual

Developing web applications with coldfusion
Table of Contents

Advertisement

Chapter 3: Querying a Database

Query Notes and Considerations

When creating queries to retrieve data, keep these guidelines in mind:
Enter the query NAME and DATASOURCE attributes in the begin CFQUERY tag.
Surround attribute settings with double quotes(").
Reference the query data by naming the query in the CFOUTPUT tag later on
the page.
Make sure that a data source exists in the ColdFusion Administrator before you
reference iit n a CFQUERY tag.
The SQL that you write is sent to the database and performs the actual data
retrieval.
Columns and tables that you refer to in your SQL statement must exist,
otherwise the query will fail.

Outputting Query Data

After you have defined a query on a page, you can use the CFOUTPUT tag with the
QUERY attribute to define the query variable that you want to output to a page. When
you use the QUERY attribute:
ColdFusion loops over all the code contained within the CFOUTPUT block,
once for each row returned from a database.
Reference specific column names within the CFOUTPUT block to output the
data to the page.
You can place text and HTML tags inside or surrounding the CFOUTPUT block
to format the data on the page.
The CFOUTPUT tag accepts a variety of optional attributes but, ordinarily, you will use
the QUERY attribute to define the name of an existing query.
To output query data on your page:
1.
Return to
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">
</CFQUERY>
4
<CFOUTPUT QUERY="EmpList">
in Studio.
empList.cfm
SELECT FirstName, LastName, Salary, Contract
FROM Employees
25

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 4.5

Table of Contents