As discussed earlier in this chapter, you build queries using the CFQUERY tag and SQL.
![]() |
To query the table: |
<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> </BODY> </HTML>
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
EmpList.cfm
:
http://127.0.0.1/myapps/emplist.cfm
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.
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 |
When creating queries to retrieve data, keep these guidelines in mind: