Example using PHP Table Class

This page demonstrates how to use the PHP Table Class to generate an HTML table. The following source code results in the table displayed below the box.


$PRODUCTS = array(
'choc_chip' => array('Chocolate Chip Cookies'1.2510.00),
'oatmeal' => array('Oatmeal Cookies'.998.25),
'brownies' => array('Fudge Brownies'1.3512.00)

// arguments: id, class
// can include associative array of optional additional attributes
$tbl = new HTML_Table('''demoTbl');
$tbl->addCaption('Dessert Favorites''cap', array('id'=> 'tblCap') );

// arguments: cell content, class, type (default is 'data' for td, pass 'header' for th)
    // can include associative array of optional additional attributes
$tbl->addCell('Single Item''''header');
$tbl->addCell('1 Dozen''''header');
$PRODUCTS as $product) {
$name$unit_price$doz_price ) = $product;
$tbl->addCell('$' number_format($unit_price2), 'num' );
$tbl->addCell('$' number_format($doz_price2), 'num' );
$tbl->addCell('All so very yummy!''foot''data', array('colspan'=>3) );


The Resulting Table

This table is the result of the above code:

Dessert Favorites
Product Single Dozen
Chocolate Chip Cookies $1.25 $10.00
Oatmeal Cookies $0.99 $8.25
Fudge Brownies $1.35 $12.00
All so very yummy!

Download and Documentation

The PHP Table Class and examples are included in a download file. Documentation is also provided.