24
Developing Web Applications with ColdFusion
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
emplist.cfm
in
myapps
under the Web root directory. For
example, the directory path on your machine may be:
C:\INETPUB\WWWROOT\myapps
on Windows NT
4.
Return to your browser and enter the following URL to view
EmpList.cfm
:
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
Description
<CFQUERY NAME="EmpList"
DATASOURCE="CompanyInfo">
Query the database specified in the
CompanyInfo datasource
SELECT FirstName, LastName,
Salary, Contract
FROM Employees
Get information from the FirstName,
LastName, Salary, and Contract fields in
the Employees table
</CFQUERY>
End the CFQUERY block
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...