|
PHP Class table (คลาสสำหรับแสดงผลข้อมูลในรูปแบบตาราง) |
PHP class table PHP class table (คลาสสำหรับแสดงผลข้อมูลในรูปแบบตาราง)
Class table version latest version
Table.class.php
<?php
/******************************************************************************
*
* Name: Table.class.php
* Purpose: Display table with PHP classes.
* Author: Narong Rammanee
*
******************************************************************************
*
* Copyright 2010 Narong <[email protected]>
*
* This class is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This class is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
******************************************************************************/
class Table
{
/**
* HTML Table Tag Attributes
* @var string
*/
private $attributes;
/**
* HTML Table Tag caption.
* @var string
*/
private $caption;
/**
* Highlight table rows.
* @var array
*/
private $highlight = array();
/**
* Table header array contain title and css.
* @var array
*/
private $header = array();
/**
* Table data array
* @var array
*/
private $data = array();
/**
* Constructor
* Initialization that the object may need before it is used.
*
* @param $attributes
* @param $header
* @param $data
* @param $highlight
* @param $caption
* @return No value is returned.
*/
public function __construct($attributes=null, $header=null, &$data=null, $highlight=null, $caption=null)
{
self::setTable($attributes, $header, $data, $highlight, $caption);
}
/**
* Set table
*
* @param $attributes
* @param $header
* @param $data
* @param $highlight
* @param $caption
* @return No value is returned.
*/
public function setTable($attributes, $header, &$data, $highlight, $caption)
{
$this->attributes = $attributes;
$this->header = $header;
$this->data = $data;
$this->highlight = $highlight;
$this->caption = $caption;
}
/**
* Create table
*
* @return HTML table.
*/
public function getTable()
{
$html = '<table ' . $this->attributes . '>';
$html .= '<caption>' . $this->caption . '</caption>';
$html .= '<thead>' . self::setTableHeader() . '</thead>';
$html .= '<tbody>' . self::setTableData() . '</tbody>';
$html .= '</table>';
return $html;
}
/**
* Set table header
*
* @return HTML Table header.
*/
private function setTableHeader()
{
$html = '<tr>';
if (!empty($this->header))
foreach ($this->header['title'] as $key=>$value)
$html .= '<th ' . $this->header['css'][$key] . '>' . $value . '</th>';
else
$html .= '<th class="txt-err">Please set header variable</th>';
$html .= '</tr>';
return $html;
}
/**
* Set table data
*
* @return HTML Table data
*/
private function setTableData()
{
$html = '';
if ($this->data) {
foreach ($this->data as $key=>$rows) {
$highlight = ($key%2 == 1) ? $this->highlight[0] : $this->highlight[1];
$html .= '<tr ' . $highlight . '>';
foreach ($rows as $value)
$html .= '<td>' . $value . '</td>';
$html .= '</tr>';
}
} else {
$html .= '<span class="txt-err">No data</span>';
}
return $html;
}
}
|
|
|
|
|
|
|
|
By : |
ranarong
|
|
Article : |
บทความเป็นการเขียนโดยสมาชิก หากมีปัญหาเรื่องลิขสิทธิ์ กรุณาแจ้งให้ทาง webmaster ทราบด้วยครับ |
|
Score Rating : |
|
|
Create Date : |
2010-12-08 |
|
Download : |
No files |
|
Sponsored Links |
|
|
|
|
|
|