Using <cfoutput> to Display Query Results - Exercise

Contact Us or call 1-877-932-8228
Using <cfoutput> to Display Query Results - Exercise

Using <cfoutput> to Display Query Results

Duration: 10 to 20 minutes.

In this exercise, you will modify the demo we have just seen so that the records are output as a table rather than as a list.

  1. Open DatabaseBasics/Exercises/cfoutput.cfm in your editor.
  2. Fix the code so that each record is displayed as a row as shown in the screenshot below:

Solution:

DatabaseBasics/Solutions/cfoutput.cfm
<cfquery name="getUsers" datasource="#APPLICATION.datasource#">
	SELECT firstname, lastname, email
	FROM Users
</cfquery>

<html>
<head>
<title>Using cfoutput</title>
</head>
<body>
<table border="1">
<tr>
	<th>FirstName</th>
	<th>LastName</th>
	<th>Email</th>
</tr>
<cfoutput query="getUsers">
	<tr>
		<td>#firstname#</td>
		<td>#lastname#</td>
		<td><a href="mailto:#email#">#email#</a></td>
	</tr>
</cfoutput>
</table>
</body>
</html>
Next