View comments | RSS feed

cfoutput

Description

Displays the results of a database query or other operation.

Category

Data output tags

Syntax

<cfoutput 
  query = "query_name"
  group = "query_column"
  groupCaseSensitive = "Yes" or "No"
  startRow = "start_row"
  maxRows = "max_rows_output">
</cfoutput>

See also

cfcol, cfcontent, cfdirectory, cftable

History

New in ColdFusion MX: On Windows, if the cfdirectory tag action = "list", the tag does not return the directory entries "." (dot) or ".." (double dot), which represent "the current directory" and "the parent directory." (In earlier releases, it returned all the entries.)

CFML code such as the following, which was acceptable in ColdFusion 5, might cause incorrect output in ColdFusion MX:

<cfdirectory action = "list" directory="c:\" name="foo">
Files in c:\<br>
<cfoutput query="foo" startrow=3>
  #name#<br>
</cfoutput>

CFML code such as the following, which was acceptable in ColdFusion 5, is acceptable in ColdFusion MX, although it is unnecessary:

<cfdirectory directory="c:\" name="foo">
Files in c:\<br>
<cfoutput query="foo" 
  <cfif NOT foo.name is "." AND NOT foo.name is ".."> 
    #name#<br>
  </cfif>
</cfoutput>

Attributes

Attribute Req/Opt Default Description
query
Optional

Name of cfquery from which to draw data for output section.
group
Optional

Query column to use when you group sets of records. Use if you retrieved a record set ordered on a query column. For example, if a record set is ordered on "Customer_ID" in the cfquery tag, you can group the output on "Customer_ID." Case-sensitive. Eliminates adjacent duplicates when data is sorted.
groupCaseSensitive
Optional
Yes
Boolean. Whether to group by case. If the query attribute specifies a query object that was generated by a case-insensitive SQL query. To keep record set intact, set to "No".
startRow
Optional
1
Row from which to start output.
maxRows
Optional

Maximum number of rows to display.

Usage

To nest cfoutput blocks, you must specify the group and query attributes at the top-most level, and the group attribute for each inner block except the innermost cfoutput block.

This tag requires an end tag.

Example

<!--- run a sample query --->
<cfquery name = "GetCourses" dataSource = "cfsnippets">
  SELECT Dept_ID, CorName, CorLevel
  FROM courseList
  ORDER by Dept_ID, CorLevel, CorName
</cfquery>
<h3>cfoutput Example</h3>
<p>cfoutput tells ColdFusion Server to begin processing, and then 
to hand back control of page rendering to the web server.
<p>For example, to show today's date, you could write #DateFormat("#Now()#"). 
If you enclosed that expression in cfoutput, the result would be
<cfoutput>#DateFormat(Now())#</cfoutput>.

<p>In addition, cfoutput may be used to show the results of a query 
operation, or only a partial result, as shown:

<p>There are <cfoutput>#getCourses.recordCount#</cfoutput> total records 
in our query. Using the maxRows parameter, we are limiting our 
display to 4 rows.
<p><cfoutput query = "GetCourses" maxRows = 4>
  <PRE>#Dept_ID#  #CorName#  #CorLevel#</PRE>
  </cfoutput>

<p>cfoutput can also show the results of a more complex expression,
such as getting the day of the week from today's date. We first
extract the integer representing the Day of the Week from
the server function Now() and then apply the result to
the DayofWeekAsString function:

<br>Today is #DayofWeekAsString(DayofWeek(Now()))#
<br>Today is <cfoutput>#DayofWeekAsString(DayofWeek(Now()))#</cfoutput>

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


sgilson102 said on Jul 1, 2002 at 6:37 PM :
Folks, in trying to help point someone to some docs on using CFOUTPUT with the GROUP attribute, I was surprised to find that I couldn't find any example of it in the docs. There's none shown here, and despite even doing a search using the search features on my local copy of the docs, I couldn't find any example in the "Developing CF Apps" book.

Can you confirm if there is an example showing this elsewhere, and if so, offer a link here (in the comments and in future versions in the page itself). It's just not obvious to most folks how to interpret the instructions above about nesting CFOUTPUT within CFOUTPUT GROUP.
ctina said on Jul 11, 2002 at 6:39 PM :
I entered bug 46802 to update DWA and/or Eon examples.
See also forums, several comments and code examples on this:
Search cfoutput AND group
http://webforums.macromedia.com/coldfusion/
--Christina
LisaJ said on Oct 21, 2003 at 1:14 PM :
In reference to the cfoutput tag description, the text states "To nest cfoutput blocks, you must specify the group and query attributes at the top-most level, and the group attribute for each inner block except the innermost cfoutput block", but there is no example.
This is the type of complex code example that should be included in the reference guide so that the user doesn't have to pull out other books to see it in action.
eibhinn said on Nov 14, 2003 at 10:30 AM :
<cfquery name="getBooks" datasource="libraryDB">
select * from library order by genre;
</cfquery>
<cfoutput query="getBooks" group="genre">
<b>#genre#</b><br>
<cfoutput>
#ISBN#<br>
<i>#title#</i><br>
#author#<br>
<br>
</cfoutput>
</cfoutput>

-----------------------------------------------------------

<b>Childrens</b><br>

0394823370<br>
<i>The Lorax</i><br>
Dr. Seuss<br>

<br>

0679885722<br>
<i>Oh, Baby, the Places You'll Go</i><br>
Tish Rabe, Dr. Seuss<br>
<br>


<b>Fiction</b><br>

0380815931<br>

<i>In the Beginning...was the Command Line</i><br>
Neal Stephenson<br>
<br>

0553380958<br>
<i>Snow Crash</i><br>
Neal Stephenson<br>

<br>


<b>Reference</b><br>

0596003803<br>
<i>Programming ColdFusion MX</i><br>
Rob Brooks-Bilson, Paula Ferguson (Editor)<br>
<br>

0321125169<br>

<i>ColdFusion MX Web Application Construction Kit</i><br>
Ben Forta, Nate Weiss, Leon Chalnick, Angela Buraglia, With Angela C. Buraglia<br>
<br>

0321180585<br>
<i>Certified Macromedia ColdFusion MX Developer Study Guide</i><br>
Ben Forta<br>

<br>
evonbart said on Jun 21, 2004 at 12:53 PM :
Interesting. Displaying data is probably one of THE most common function a developer will build into their application and nobody in the CF house has got it right yet.

Since there is no clearcut way to nest cfoutputs say from two unrelated queries, I'll have to devise another cockeyed method to display my data.

In ASP I can use either method of dumping the data into an array then display it OR just pull it straight from the database by wrapping one layer of output over another as many times as necessary. Either method took take less time to write than this comment will and both are as easy as the other.

CF, however, still - going on v6+ now, has not come close to making either method work properly (cfoutput or arrays) and I love spending hours and hours pouring through incomplete documentation to find I can't do what I need anyway. I will say their documentation has improved since when I started with v3.

If I had my say in what is used to build my apps it would never be CF just because of the terrible time I have finding decent dev documentation, both here and throughout the web . D minus guys!!
No screen name said on Aug 16, 2004 at 1:42 PM :
I know there are many CF developers and reqular users who encounter the problem of nesting CFOUTPUT statements. If it's one thing I know from my experience, it's that there is a way to do (almost) anything, and adding the capability of nesting CFOUTPUT statements would greatly bolster CF's power.

Specifically I am using a form to allow record editing. But I use a CFSELECT for a couple of fields. This should be possible. Thanks.
No screen name said on Dec 21, 2004 at 11:28 AM :
I hope I'm not pointing out the obvious to most, but the way I handle nesting is I have CFOUPUT as my outer layer, and nested query output, I just use a CFLOOP with query attribute. This allows me with with unlimited nesting with full control.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/Tags-pt211.htm