Location: PHPKode > scripts > CTable > ctable/usage.txt
Class:   CTable
Author:  David Higgins
Written: 10/20/2002

USAGE INSTRUCTIONS:

To use this class, simply create an instance of it, like so:

    $table = new CTable();

You will then need to assign the number of rows for the class, this is done using the Rows() method, like so:

    $table->Rows(5);

You will also need to define the number of cells for the table, in much the same way you define the Rows, using the Cells() method, like this:

    $table->Cells(10);

You can now set the data contained within the cells, like this:

    for($x=1;$x<=$table->GetRows(); $x++) {
      for($y=1;$y<=$table->GetCells(); $y++) {
        $table->SetData("x($x) y($y)", $x, $y);
      }
    }

The above is a loop that fills each cell in the table with the row and cell number ... the output should look similiar to this:

    x(1) y(1) | x(1) y(2) | x(1) y(3)
    x(2) y(1) | x(2) y(2) | x(2) y(3)
    x(3) y(1) | x(3) y(2) | x(3) y(3)

After you have placed data within the table, you must then Generate() it for it to be displayed on the screen.  This is done with the Generate() method, like so:

    $table->Generate();

You may additionally free up some memory, by calling the Release() method, like so:

    $table->Release();


ADDITIONAL FEATURES:

You may wish to alter the table's class, border, width, cellpadding, cellspacing, or possibly its style attribute.  You can do this using either the setHeader() method, or by calling the setClass, setBorder, setWidth, setCellpadding or setCellspacing methods, similiar to this:

    $table = new CTable();
    // setHeader must be called before any other Header methods
    // setHeader rewrites the current Header, this is why!
    $table->setHeader('style="border: thin solid red"');
    $table->setCellspacing(5);
    $table->setCellpadding(0);
    $table->setBorder(1);
    $table->Rows(5);
    $table->Cells(2);
    $table->SetData("TEST", 1, 2);
    $table->Generate();
    $table->Release();
    unset($table);


I created a simple function called GenerateTableOutput which is included in the package... it shows how to take advantage of some of the advanced features, such as the setHeader methods ... 
Return current item: CTable