CFM Tutorial     

Cold Fusion Tag: <CFOUTPUT></CFOUTPUT>


Description

<CFOUTPUT> is used to output the results of a <CFQUERY>, or any time text includes variables that are to be expanded. If <CFOUTPUT> is used to process the results of a <CFQUERY> tag, any code between <CFOUTPUT> AND </CFOUTPUT> is repeated once for every row. can be used with the GROUP attribute to specify a data group. Data that is grouped together is displayed so that only the first occurrence of each value is output.

Syntax

<CFOUTPUT QUERY="Query Name" 
   MAXROWS="Maximum Rows"
   STARTROW="Start Row" 
   GROUP="Group Column">
   Code
 </CFOUTPUT>

<CFOUTPUT> attributes are described in the following table:

Attribute Description Notes
GROUP Column to group on This optional attribute allows you to define output groups.
MAXROWS Maximum rows to display This optional attribute specifies the maximum number of rows to diplay. If omitted, all rows are displayed.
QUERY Query name This optional query name is used to refer to the query results within <CFOUTPUT> text.
STARTROW First row to diplay This optional attribute specifies the output start row.

Example: Any time you use variables or fields with your template, you must enclose them with <CFOUTPUT> tags as shown in the following example, or else the field name will be sent as is and not expanded.

<CFOUTPUT>
Hi #name#, thanks for dropping by again.<p>
You have now visited us #NumberFormat(visits)# times since your 
first visit on #dateFormat(first_visit)#.
</CFOUTPUT>
The next example use <CFOUTPUT> to dislay the results of a query in an unordered list.
<UL>
<CFOUTPUT QUERY="employees">
	<li> #LastName#, #FirstName# - Ext: #PhoneExtension# </li>
</CFOUTPUT>
</UL>
To group output results you can use the GROUP attribute as shown in the following example which lists employees within departments.
<UL>
<CFOUTPUT QUERY="Employee" GROUP="Department">
	<li><b>#Department#</b></li>
	    <ul>
	        <CFOUTPUT>
		    <li>#LastName#,#FirstName# - Ext: #PhoneExtension#</li>
		</CFOUTPUT>
	    </ul>
	</li>
</CFOUTPUT>
</UL>

    References

    (1) the Cold Fusion Web Application Construction Kit, Second Edition.

KHMERCyber.com ©2008