Working with Queries and Data
Working with Queries and Data
The ability to generate and display query data is one of the most important and
flexible features of ColdFusion. The following sections further your understanding of
using queries and displaying their results. Some of these tools are effective for
presenting any data, not just query results.
Using HTML tables to display query results
You displayed each row of data from the Employee table, but the information was
unformatted. You can use HTML tables to control the layout of information on the
page. In addition, you can use CFML functions to format individual pieces of data,
such as dates and numeric values.
You can use HTML tables to specify how the results of a query appear on a page. To
do so, you put the
tag to put column labels in a header row. To create a row in the table for each row in
the query results, put the
To put the query results in a table:
1
2
cfoutput
Return to the file actionpage.cfm in ColdFusion Studio.
Modify the page so that it appears as follows:
<html>
<head>
<title>Retrieving Employee Data Based on Criteia from Form</title>
</head>
<body>
<cfquery name="GetEmployees" datasource="CompanyInfo">
SELECT FirstName, LastName, Salary
FROM Employee
WHERE LastName='#Form.LastName#'
</cfquery>
<h4>Employee Data Based on Criteria from Form</h4>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Salary</th>
</tr>
<cfoutput query="GetEmployees">
<tr>
<td>#FirstName#</td>
<td>#LastName#</td>
<td>#Salary#</td>
</tr>
</cfoutput>
</table>
<br>
<cfoutput>Contractor: #Form.Contractor#</cfoutput>
tag inside the table tags. You can also use the HTML
block inside the
tr
cfoutput
tag.
49
th
Need help?
Do you have a question about the COLDFUSION 5-DEVELOPING and is the answer not in the manual?
Questions and answers