As discussed earlier in this chapter, you build queries using the cfquery
tag and SQL.
<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> </body> </html>
apps
under the Web root directory. For example, the directory path on your machine might be:C:\INETPUB\WWWROOT\myapps on Windows NT
http://127.0.0.1/myapps/emplist.cfm
The ColdFusion Server creates the EmpList data set, but only HTML and text is sent back to the browser so you just see the heading "Employee List". 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. The following table describes the code and its function:
When creating queries to retrieve data, keep the following guidelines in mind:
name
and datasource
attributes in the begin cfquery
tag.
cfquery
tag. Alternatively, use the dbtype = "dynamic"
and queryString
attributes to dynamically specify a database.cfoutput
, cfgrid
, cftable
, cfgraph
, or cftree
later on the page.