<?php
/*
TableMakerStyle.php
An example of using a style sheet with the TableMaker PHP class
*/
// Edit $includeLib so that it points to the library where TableMaker.inc is stored
$includeLib = '../PhpInclude/';
require_once ($includeLib . 'HTMLTagMaker.inc');
require_once ($includeLib . 'TableMaker.inc');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>TableMaker style sheet example</TITLE>
<STYLE type="text/css">
.captionStyle {
font-weight : bold;
text-align : left;
}
.trEven {
/* Rows with even numbers */
color : Black;
background-color : White;
}
.trUneven {
/* Rows with uneven numbers */
background-color : Yellow;
color : Black;
}
.trSummary {
/* Row containing summary data */
font-weight : bold;
}
.tdName {
/* Table data cells containing names */
padding-right : 16;
}
.tdFigure {
/* Table data cell with figures */
text-align : right;
}
</style>
</HEAD>
<BODY>
<H1>TableMaker style sheet example</H1>
<?php
// Define an array of data. This could be data read from a database
$population = array (
array('Country' => 'Austria', 'Pop' => 8.121),
array('Country' => 'Belgium', 'Pop' => 10.262),
array('Country' => 'Denmark', 'Pop' => 5.349),
array('Country' => 'Finland', 'Pop' => 5.181),
array('Country' => 'France', 'Pop' => 59.521),
array('Country' => 'Germany', 'Pop' => 82.193),
array('Country' => 'Greece', 'Pop' => 10.565),
array('Country' => 'Ireland', 'Pop' => 3.82),
array('Country' => 'Italy', 'Pop' => 57.844),
array('Country' => 'Luxemburg', 'Pop' => 0.441),
array('Country' => 'Netherlands', 'Pop' => 15.983),
array('Country' => 'Portugal', 'Pop' => 10.023),
array('Country' => 'Spain', 'Pop' => 39.49),
array('Country' => 'Sweden', 'Pop' => 8.883),
array('Country' => 'United Kingdom', 'Pop' => 59.832),
);
$dec = 2; // Decimals in population figures
// Create new table
$euPopTable = new TableMaker();
// Define elements with class attributes
$euPopTable -> defineRow ('trEven', array('class' => 'trEven'));
$euPopTable -> defineRow ('trUneven', array('class' => 'trUneven'));
$euPopTable -> defineDataCell ('tdFigure', array('class' => 'tdFigure'));
$euPopTable -> defineDataCell ('tdName', array('class' => 'tdName'));
// Add a caption
$euPopTable -> addCaption ('Population of the EU countries in millions (2001):',
array('class' => 'captionStyle'));
// Place a horizontal ruler above the first row
$euPopTable -> addRow();
$euPopTable -> addData('<hr>', 'ruler', array('colspan' => 2));
// Add contents of the data array
$totalPop = 0; // Keep count of total population
$rowClass = '';
$j = sizeof($population);
for ($i = 0; $i < $j; $i++) {
$rowClass = ($i % 2 == 0) ? 'trEven' : 'trUneven';
$euPopTable -> addRow($rowClass);
$euPopTable -> addData($population[$i]['Country'], 'tdName');
$euPopTable -> addData(number_format($population[$i]['Pop'], $dec), 'tdFigure');
$totalPop += $population[$i]['Pop'];
}
// Add a horizontal ruler below the table body
$euPopTable -> addRow();
$euPopTable -> addData('<hr>', 'ruler');
// Print the total population
$euPopTable -> addRow('default', array('class' => 'trSummary'));
$euPopTable -> addData('Total population', 'tdName');
$euPopTable -> addData(number_format($totalPop, $dec), 'tdFigure');
// Finally, write the table
$euPopTable -> writeTable();
?>
<P>Source: Eurostat</P>
</BODY>
</HTML>
|