# CFTABLE

Builds a table in your ColdFusion page. Use the CFCOL tag to define column and row characteristics for a table. CFTABLE renders data either as preformatted text, or, with the HTMLTABLE attribute, as an HTML table. Use CFTABLE to create tables if you don't want to write your own HTML TABLE tag code, or if your data can be well presented as preformatted text. See Usage for information about using the CFCOL tag with the CFTABLE tag.

### Syntax

    <CFTABLE QUERY="query_name"
        MAXROWS="maxrows_table"
        COLSPACING="number_of_spaces"
        HEADERLINES="number_of_lines"
        HTMLTABLE
        BORDER
        COLHEADERS
        STARTROW="row_number">

    </CFTABLE>

#### QUERY

Required. The name of the CFQUERY from which you want to draw data.

#### MAXROWS

Optional. Specifies the maximum number of rows you want to display in the table.

#### COLSPACING

Optional. Indicates the number of spaces to insert between columns (default is 2).

#### HEADERLINES

Optional. Indicates the number of lines to use for the table header (the default is 2, which leaves one line between the headers and the first row of the table).

#### HTMLTABLE

Optional. Renders the table as an HTML 3.0 table.

#### BORDER

Optional. Adds a border to the table. Use only when you specify the HTMLTABLE attribute for the table.

#### COLHEADERS

Optional. Displays headers for each column, as specified in the CFCOL tag.

#### STARTROW

Optional. Specifies the query row from which to start processing.

### Usage

You can use the CFCOL tag to align the data in the table , specify the width of each column, and provide column headers.

Note | CFCOL is the only tag that you can nest within CFTABLE.

### Example

    <!--- This example shows the use of CFCOL and CFTABLE
    to align information returned from a query --->

    <!--- This query selects employee information from the
    cfsnippets datasource --->
    <CFQUERY NAME="GetEmployees" DATASOURCE="cfsnippets">
    SELECT Emp_ID, FirstName, LastName, EMail, Phone, Department
    FROM Employees
    </CFQUERY>

    <HTML>
    <HEAD>
    <TITLE>CFTABLE Example</TITLE>
    </HEAD>

    <BODY>
    <H3>CFTABLE Example</H3>

    <!--- Note the use of the HTMLTABLE attribute to display the
    CFTABLE as an HTML table, rather simply as PRE formatted information --->
    <CFTABLE QUERY="GetEmployees" STARTROW="1" COLSPACING="3" HTMLTABLE>
    <!--- each CFCOL tag sets the width of a column in the table,
    as well as specifying the header information and the text/CFML
    with which to fill the cell --->
        <CFCOL HEADER = "<B>ID</B>"
            ALIGN = "Left"
            WIDTH = 2
            TEXT  = "#Emp_ID#">

        <CFCOL HEADER = "<B>Name/Email</B>"
            ALIGN = "Left"
            WIDTH = 15
            TEXT  = "<a href='mailto:#Email#'>#FirstName# #LastName#</A>">

        <CFCOL HEADER = "<B>Phone Number</B>"
            ALIGN = "Center"
            WIDTH = 15
            TEXT  = "#Phone#">
    </CFTABLE>

    </BODY>
    </HTML>