Building Queries - MACROMEDIA COLDFUSION 4.5-DEVELOPING WEB Develop Manual

Developing web applications with coldfusion
Table of Contents

Advertisement

24

Building Queries

As discussed earlier in this chapter, you build queries using the CFQUERY tag and SQL.
To query the table:
1.
Create a new application page.
2.
Edit the page so that it appears as follows:
<HTML>
<HEAD>
<TITLE>Employee List</TITLE>
</HEAD>
<BODY>
<H1>Employee List</H1>
4
<CFQUERY NAME="EmpList" DATASOURCE="CompanyInfo">
4
SELECT FirstName, LastName, Salary, Contract
4
FROM Employees
4
</CFQUERY>
</BODY>
</HTML>
3.
Save the page as
example, the directory path on your machine may be:
C:\INETPUB\WWWROOT\myapps
4.
Return to your browser and enter the following URL to view
http://127.0.0.1/myapps/emplist.cfm
5.
View source in the browser.
The ColdFusion EmpList data set is created by ColdFusion Server, but only HTML
and text is sent back to the browser. To display the data set on the page, you must
code tags and variables to output the data.
Code Review
The query you just created retrieves data from the CompanyInfo database.
Code
<CFQUERY NAME="EmpList"
DATASOURCE="CompanyInfo">
SELECT FirstName, LastName,
Salary, Contract
FROM Employees
</CFQUERY>
in
under the Web root directory. For
emplist.cfm
myapps
on Windows NT
Description
Query the database specified in the
CompanyInfo datasource
Get information from the FirstName,
LastName, Salary, and Contract fields in
the Employees table
End the CFQUERY block
Developing Web Applications with ColdFusion
EmpList.cfm
:

Advertisement

Table of Contents
loading
Need help?

Need help?

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

Subscribe to Our Youtube Channel

This manual is also suitable for:

Coldfusion 4.5

Table of Contents