Tables
|
|
|
|
<? class HTML_table {
// number of the table columns var $col_number = 1;
// number of the table rows var $row_number = 1;
// style of the table border var $border_style = "";
// table width in absolute or percent var $table_width = "";
// columns widths array var $col_width = array(); // columns names array var $col_name = array(); // alignement of the cells containing column names var $col_name_align = array(); // border style of the cells containing column names var $col_name_border = array(); // style of the TH cells var $col_name_style = array();
// cells contents var $data = array(); // cells background colors var $cell_color = array(); // cells horizontal alignement var $cell_align = array(); // cells vertical alignement var $cell_valign = array(); // cells height
var $cell_height = array(); // cell style var $cell_style = array();
/* html code that will be written between <TABLE> und the first tag
of the table, e.g. for form */ var $hidden_header = "";
/* html code that will be written between the last first tag
of the table and the </TABLE>, e.g. for form */ var $hidden_footer = "";
function HTML_table() {
$this->column_width[0] = "";
$this->column_name[0] = "";
}
function setTableWidth($width) {
$this->table_width = $width;
}
function setColsNumber($num) {
$this->col_number = $num;
}
function setColWidth($col, $width) {
$this->col_width[$col] = $width;
if(($col <> 0)&&($this->col_width[0] ==""))
{$this->col_width[0] = 0;}
}
function setColumnsWidth($array) {
$col = 0;
foreach($array as $k) {
$this->setColWidth($col, $k);
$col++;
}
}
function setColName($col, $name) {
$this->col_name[$col] = $name;
if(($col <> 0)&&($this->col_name[0]==""))
{$this->col_name[0] = " ";}
}
function setColumnsName($array) {
$col = 0;
foreach($array as $k) {
$this->setColName($col, $k);
$col++;
}
}
function setColNameAlign($col, $align) {
$this->col_name_align[$col] = $align;
if(($col <> 0)&&($this->col_name_align[0]==""))
{$this->col_name_align[0] = " ";}
}
function setColumnsNameAlign($array) {
$col = 0;
foreach($array as $k) {
$this->setColNameAlign($col, $k);
$col++;
}
}
function setColNameBorder($col, $border) {
$this->col_name_border[$col] = $border;
if(($col <> 0)&&($this->col_name_border[0]==""))
{$this->col_name_border[0] = " ";}
}
function setColNameStyle($col, $style) {
$this->col_name_style[$col] = $style;
if(($col <> 0)&&($this->col_name_style[0]==""))
{$this->col_name_style[0] = " ";}
}
function setColumnsNameStyle($array) {
$col = 0;
foreach($array as $k) {
$this->setColNameStyle($col, $k);
$col++;
}
}
function setRowsNumber($num) {
$this->row_number = $num;
}
function setBorderStyle($border) {
$this->border_style = $border;
}
function setCellColor($row, $col, $color) {
$this->cell_color[$row][$col] = $color;
}
function setRowColor($row, $color) {
for($col = 0; $col < $this->col_number; $col++) {
$this->cell_color[$row][$col] = $color;
}
}
function setColColor($col, $color) {
for($row = 0; $row < $this->row_number; $row++) {
$this->cell_color[$row][$col] = $color;
}
}
function setCellAlign($row, $col, $align) {
$this->cell_align[$row][$col] = $align;
}
function setCellValign($row, $col, $valign) {
$this->cell_valign[$row][$col] = $valign;
}
function setCellHeight($row, $col, $height) {
$this->cell_height[$row][$col] = $height;
}
function setRowHeight($row, $height) {
for($col = 0; $col < $this->col_number; $col++) {
$this->setCellHeight($row, $col, $height);
}
}
function insertCell($row, $col, $content) {
$this->data[$row][$col] = $content;
}
function insertRow($row, $content) {
$col = 0;
foreach($content as $k) {
$this->insertCell($row, $col, $k);
$col++;
}
}
function insertHiddenHeader($string) {
$this->hidden_header .= $string;
}
function insertHiddenFooter($string) {
$this->hidden_footer .= $string;
}
function returnTableOpenTag() {
$output = "";
$output .= "n".'<TABLE CELLSPACING="1" CELLPADDING="1"';
if($this->border_style <> "") {
$output .=" border="".$this->border_style."" ";
}
if($this->table_width <> "") {
$output .="width="".$this->table_width."" ";
}
$output .= ">n";
return $output;
}
function returnTableHeader() {
$output = "";
$output .= "<TR align = "center">n";
if(($this->col_width[0] <> "")||($this->col_name[0] <> "")) {
for($col = 0; $col < $this->col_number; $col++) {
$output .= '<TH';
if($this->col_width[$col] <> "") {
$output .= " width="".$this->col_width[$col].""";
}
if($this->col_name_style[$col] <> "") {
$output .= " style="".$this->col_name_style[$col].""";
}
$output .= ">";
if($this->col_name[$col] <> "") {
$output .= " ".$this->col_name[$col];
}
else {
$output .= " ";
}
$output .= "</TH>n";
}
}
$output .= "</TR>";
$output .= "n";
return $output;
}
function returnRow($row) {
$output = "";
for($col = 0; $col < $this->col_number; $col++) {
$output .= "<TD";
if($this->cell_color[$row][$col] <> "") {
$output .= " bgcolor="".$this->cell_color[$row][$col].""";
}
if($this->cell_align[$row][$col] <> "") {
$output .= " align="".$this->cell_align[$row][$col].""";
}
if($this->cell_valign[$row][$col] <> "") {
$output .= " valign="".$this->cell_valign[$row][$col].""";
}
if($this->cell_height[$row][$col] <> "") {
$output .= " height="".$this->cell_height[$row][$col].""";
}
$output .= ">";
$output .= $this->data[$row][$col];
$output .= " "."</TD>n";
}
return $output;
}
function returnHTML() {
$output = "";
$output .= $this->returnTableOpenTag();
$output .= $this->hidden_header."n";
$output .= $this->returnTableHeader();
for($k = 0; $k < $this->row_number; $k++) {
$output .= "<TR valign="middle">n";
$output .= $this->returnRow($k);
$output .= "</TR>n";
}
$output .= $this->hidden_footer."n";
$output .= "</TABLE>n";
return $output;
}
} ?>
|
|
|
Usage Example
|
<TABLE CELLSPACING="1" CELLPADDING="1"width="100%" >
<TR align = "center">
<TH width="13%" style="border-style: solid; border-color: #88BBFF; border-width: 2px"> <a href="?namesort=descending&inputname=">Name</a></TH>
<TH width="15%" style="border-style: solid; border-color: #88BBFF; border-width: 2px"> <a href="?vornamesort=ascending&inputname=">First Name</a></TH>
<TH width="18%" style="border-style: solid; border-color: #88BBFF; border-width: 2px"> <a href="?emailsort=ascending&inputname=">Email</a></TH>
<TH width="8%" style="border-style: solid; border-color: #88BBFF; border-width: 2px"> <a href="?internsort=ascending&inputname=">From</a></TH>
<TH width="8%" style="border-style: solid; border-color: #88BBFF; border-width: 2px"> <a href="?mobilsort=ascending&inputname=">To</a></TH>
</TR>
<TR valign="middle">
<TD bgcolor="#396DB5" height="30">Bush  </TD>
<TD bgcolor="#396DB5" height="30">George  </TD>
<TD bgcolor="#396DB5" height="30"><a href="mailto:"></a>  </TD>
<TD bgcolor="#396DB5" height="30">1988  </TD>
<TD bgcolor="#396DB5" height="30">1992  </TD>
</TR>
<TR valign="middle">
<TD bgcolor="#396DA5" height="30">Carter  </TD>
<TD bgcolor="#396DA5" height="30">Jimmy  </TD>
<TD bgcolor="#396DA5" height="30"><a href="mailto:"></a>  </TD>
<TD bgcolor="#396DA5" height="30">1976  </TD>
<TD bgcolor="#396DA5" height="30">1980  </TD>
</TR>
<TR valign="middle">
<TD bgcolor="#396DB5" height="30">Clinton  </TD>
<TD bgcolor="#396DB5" height="30">Billy  </TD>
<TD bgcolor="#396DB5" height="30"><a href="mailto:"></a>  </TD>
<TD bgcolor="#396DB5" height="30">1992  </TD>
<TD bgcolor="#396DB5" height="30">2000  </TD>
</TR>
<TR valign="middle">
<TD bgcolor="#396DA5" height="30">Eisenhower  </TD>
<TD bgcolor="#396DA5" height="30">Dwight David  </TD>
<TD bgcolor="#396DA5" height="30"><a href="mailto:"></a>  </TD>
<TD bgcolor="#396DA5" height="30">1952  </TD>
<TD bgcolor="#396DA5" height="30">1960  </TD>
</TR>
<TR valign="middle">
<TD bgcolor="#396DB5" height="30">Jefferson  </TD>
<TD bgcolor="#396DB5" height="30">Tommy  </TD>
<TD bgcolor="#396DB5" height="30"><a href="mailto:"></a>  </TD>
<TD bgcolor="#396DB5" height="30">1796  </TD>
<TD bgcolor="#396DB5" height="30">1808  </TD>
</TR>
<TR valign="middle">
<TD bgcolor="#396DA5" height="30">Kennedy  </TD>
<TD bgcolor="#396DA5" height="30">John Fitzgerarld  </TD>
<TD bgcolor="#396DA5" height="30"><a href="mailto:"></a>  </TD>
<TD bgcolor="#396DA5" height="30">1960  </TD>
<TD bgcolor="#396DA5" height="30">1963  </TD>
</TR>
<TR valign="middle">
<TD bgcolor="#396DA5" height="30">Lincoln  </TD>
<TD bgcolor="#396DA5" height="30">Abe  </TD>
<TD bgcolor="#396DA5" height="30"><a href="mailto:"></a>  </TD>
<TD bgcolor="#396DA5" height="30">1860  </TD>
<TD bgcolor="#396DA5" height="30">1872  </TD>
</TR>
<TR valign="middle">
<TD bgcolor="#396DB5" height="30">Nixon  </TD>
<TD bgcolor="#396DB5" height="30">Richie  </TD>
<TD bgcolor="#396DB5" height="30"><a href="mailto:"></a>  </TD>
<TD bgcolor="#396DB5" height="30">1968  </TD>
<TD bgcolor="#396DB5" height="30">1974  </TD>
</TR>
<TR valign="middle">
<TD bgcolor="#396DA5" height="30">Reagan  </TD>
<TD bgcolor="#396DA5" height="30">Ronnie  </TD>
<TD bgcolor="#396DA5" height="30"><a href="mailto:"></a>  </TD>
<TD bgcolor="#396DA5" height="30">1980  </TD>
<TD bgcolor="#396DA5" height="30">1988  </TD>
</TR>
<TR valign="middle">
<TD bgcolor="#396DB5" height="30">Roosvelt  </TD>
<TD bgcolor="#396DB5" height="30">Teddy  </TD>
<TD bgcolor="#396DB5" height="30"><a href="mailto:"></a>  </TD>
<TD bgcolor="#396DB5" height="30">1900  </TD>
<TD bgcolor="#396DB5" height="30">1908  </TD>
</TR>
<TR valign="middle">
<TD bgcolor="#396DA5" height="30">Roosvelt  </TD>
<TD bgcolor="#396DA5" height="30">Frankie Delano  </TD>
<TD bgcolor="#396DA5" height="30"><a href="mailto:"></a>  </TD>
<TD bgcolor="#396DA5" height="30">1932  </TD>
<TD bgcolor="#396DA5" height="30">1945  </TD>
</TR>
<TR valign="middle">
<TD bgcolor="#396DB5" height="30">Truman  </TD>
<TD bgcolor="#396DB5" height="30">Harry  </TD>
<TD bgcolor="#396DB5" height="30"><a href="mailto:"></a>  </TD>
<TD bgcolor="#396DB5" height="30">1945  </TD>
<TD bgcolor="#396DB5" height="30">1952  </TD>
</TR>
<TR valign="middle">
<TD bgcolor="#396DA5" height="30">Washington  </TD>
<TD bgcolor="#396DA5" height="30">George  </TD>
<TD bgcolor="#396DA5" height="30"><a href="mailto:"></a>  </TD>
<TD bgcolor="#396DA5" height="30">1789  </TD>
<TD bgcolor="#396DA5" height="30">1796  </TD>
</TR>
</TABLE>
|
|
|
Rate This Script
|
|
|
|