TUTORIAL |
Table.php |
|
| by Bertrand Mansion http://www.mamasam.com/index3.html |
||
| This class was created by : Adam Daniel and Bertrand Mansion in March 2001 for PEAR (PHP Extension and Add-ons Repository) and its source code can be found at http://cvs.php.net or directly in your PHP distribution. Table.php allows you to generate HTML table without the need to include HTML tags in your PHP code.
|
||
$tableStyle = "bgcolor=#FFFFFF
border=1 width=150 cellpadding=1 cellspacing=2 "; |
$colA = array("field 1",
"field 2", "field 3", "", "<b>TOTAL</b>"); |
require_once ("/HTML/Table.php"); |
| field 1 | 10 |
| field 2 | 15 |
| field 3 | 8 |
| TOTAL | 33 |
$table->setColAttributes(1,"bgcolor=#99CCCC
align=right");$table->setRowAttributes(4,"bgcolor=#669933"); |
|
You will notice that rows and columns are defined by pointers starting from 0 and not 1. This is to be compliant with PHP arrays. |
$table->setCellAttributes(3,0,"colspan=2"); |
| field 1 | 10 |
| field 2 | 15 |
| field 3 | 8 |
|
|
|
| TOTAL | 33 |
$tableA = $table->toHTML();
|
$db = DB::connect("mysql://$dbuser:$dbpass@$dbhost/$dbname"); |
$colHeaders = array("Name",
"Firstname", "Extra"); |
$headerStyle = "bgcolor=blue
nowrap";
|
while ($row = $result->fetchrow(DB_FETCHMODE_ASSOC))
{ |
$tableB->addRow(array("","",date('Ymd')); |
| Name | Firstname | Extra |
| Picsou | Uncle | |
| Harry | Inspector | |
| Mouse | Mickey | |
| Duck | Donald | |
| Gates | William | |
| Disney | Walter | |
| Smith | John | |
| Bush | Georgie | |
| McDonald | Ronald | |
| 20010315 |
|
|
| Name | Firstname | Extra |
|---|---|---|
| Picsou | Uncle | |
| Harry | Inspector | |
| Mouse | Mickey | |
| Duck | Donald | |
| Gates | William | |
| Disney | Walter | |
| Smith | John | |
| Bush | Georgie | |
| McDonald | Ronald | |
| 20010315 |
$rowCount = $tableB->getRowCount(); |
| Name | Firstname | Extra |
|---|---|---|
| Picsou | Uncle | |
| Harry | Inspector | |
| Mouse | Mickey | |
| Duck | Donald | |
| Gates | William | |
| Disney | Walter | |
| Smith | John | |
| Bush | Georgie | |
| McDonald | Ronald | |
| 20010315 |
And last but not least, it is also possible to add a table
in a table cell, like this:
$tableB->setCellContents($rowCount-1,2,$tableA);
|
| Name | Firstname | Extra | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Picsou | Uncle | |||||||||||
| Harry | Inspector | |||||||||||
| Mouse | Mickey | |||||||||||
| Duck | Donald | |||||||||||
| Gates | William | |||||||||||
| Disney | Walter | |||||||||||
| Smith | John | |||||||||||
| Bush | Georgie | |||||||||||
| McDonald | Ronald | |||||||||||
|
||||||||||||