Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > บทความจากสมาชิก > PHP Class table (คลาสสำหรับแสดงผลข้อมูลในรูปแบบตาราง)



 
Clound SSD Virtual Server

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;
	}
}







   
Share
Bookmark.   

  By : ranarong
  Article : บทความเป็นการเขียนโดยสมาชิก หากมีปัญหาเรื่องลิขสิทธิ์ กรุณาแจ้งให้ทาง webmaster ทราบด้วยครับ
  Score Rating :
  Create Date : 2010-12-08
  Download : No files
Sponsored Links
ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่