PHP Classes

File: TableExample.php

Recommend this page to a friend!
  Classes of Oddleif Halvorsen   XHTML Table generator   TableExample.php   Download  
File: TableExample.php
Role: Example script
Content type: text/plain
Description: An example script on using the table generator.
Class: XHTML Table generator
Generates HTML tables conformant with XHTML 1.0
Author: By
Last change:
Date: 20 years ago
Size: 2,800 bytes
 

Contents

Class file image Download
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Table examples</title>
</head>

<body>
<h1>Examples on how to use the table class</h1>
<p>The class is implemented according to xhtml 1.0 strict. Se the xhtml 1.0 stric standard for details on how to use the table tag.</p>
<p>---------------------------------------------------------</p>
<?php
   
// Icluding all the files needed
   
include_once("Table.php");
    include_once(
"Tr.php");
    include_once(
"Td.php");
    include_once(
"Th.php");
?>
<h2>Example 1: Simple table</h2>
<p>A table of one row with 6 columns.</p>
<?php
    $table
= new Table();
   
$table->setBorder(1);
   
//generates a new row with 6 columns
   
$row = new Tr();
    for(
$i=0; $i<6; $i++){
       
$row->addColumn(new Td(("column " . ($i+1))));
    }
   
   
//adds the row to the table
   
$table->addRow($row);
   
    echo
$table->getHtml();
?>
<p>---------------------------------------------------------</p>
<h2>Example 2: Table with rowheaders</h2>
<p>A table of 4 rows with row headers</p>
<?php
    $table
= new Table();
   
$table->setBorder(1);
   
$table->setWidth(100, "%");
   
    for(
$x=0; $x<4; $x++){
       
//generates a new row with 6 columns
       
$row = new Tr();
       
$row->addRowheader(new Th("rowheader" . ($x+1)));
        for(
$i=0; $i<5; $i++){
           
$row->addColumn(new Td(("column " . ($i+1))));
        }
       
       
//adds the row to the table
       
$table->addRow($row);
    }
   
    echo
$table->getHtml();
?>
<p>---------------------------------------------------------</p>
<h2>Example 3: Table with multiple headers</h2>
<p>A table of 4 rows with row headers, column header and a table header</p>
<?php
    $table
= new Table();
   
$table->setBorder(1);
   
$table->setWidth(800, "px");
   
   
//sets the table header
   
$tableHeader = new Tr();
   
$header = new Th("Table header");
   
$header->setColspan(6);
   
$tableHeader->addColumn($header);
   
$table->setTableHeader($tableHeader);
   
   
//sets the column headers
   
$columnHeaders = new Tr();
    for(
$x=0; $x<6; $x++)
       
$columnHeaders->addColumn(new Th(("column header " . ($x+1))));
   
   
$table->setColumnHeaders($columnHeaders);
   
    for(
$x=0; $x<4; $x++){
       
//generates a new row with 6 columns
       
$row = new Tr();
       
$row->addRowheader(new Th("rowheader" . ($x+1)));
        for(
$i=0; $i<5; $i++){
           
$td = new Td(("column " . ($i+1)));
           
$td->setAlign("right");
           
$row->addColumn($td);
        }
       
       
//adds the row to the table
       
$table->addRow($row);
    }
   
    echo
$table->getHtml();
?>
<p>
    <a href="http://validator.w3.org/check?uri=referer"><img
            src="http://www.w3.org/Icons/valid-xhtml10"
            alt="Valid XHTML 1.0!" height="31" width="88" /></a>
</p>
</body>
</html>