WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - השוואת מחירים בסופר
ZeroLag.com
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Automatic generation of HTML code for a table. OO interface. Can define colspan, rowspan, table style, cell style, and data style. Simple, but effective.
Categories : PHP, PHP Classes, HTML, HTML and PHP Update Picture
Herman Veluwenkamp
Date : Jan 19th 2000
Grade : 3 of 5 (graded 8 times)
Viewed : 18873
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Herman Veluwenkamp
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<html>
<head>
<title>Table</title>
        
<style type="text/css">
        .header { background: yellow; text-align: center; }
</style>
        
</head>
<body>


<?
class html_table {
        var $cols = 0;
        var $rows = 0;
        var $cell = array();
        var $html = '';
        var $cell_content = '&nbsp;'; //default cell content.
        var $content_style = ''; //default content style. content is surrounded by <SPAN> tag.
        
        var $cell_style = ''; //default cell style
        var $table_style = ''; //default table style.
                                        
function cell_init() {
        return array(
                'content'=>$this->cell_content,                        // data to be inserted between <TD> tags.
                'style'=>$this->content_style,                        // if this is defined and not empty then "content" (defined above)
                                                                                                                        
                                        // is encapsulated by a <SPAN STYLE='style'> tag.
                'cell_style'=>$this->cell_style);                // if this is defined and not empty then the <TD> tag that encapsulates
                                                                                                                        
                                        // "content" has its "$cell_style" replaced by this variable.
}
        
function init($parameters) {
        if (isset($parameters['cols'])) $this->cols = $parameters['cols'];
        if (isset($parameters['rows']))$this->rows = $parameters['rows'];
        for ($row = 1; $row <= $this->rows; $row++) {
                for ($col = 1; $col <= $this->cols; $col++) {
                        $this->cell[$row][$col] = $this->cell_init();
                }
        }
}

function add_rows($num_rows) {
        for ($row = 1; $row <= $num_rows; $row++) {
                for ($col = 1; $col <= $this->cols; $col++) {
                        $this->cell[$row + $this->rows][$col] = $this->cell_init();
                }
        }
        $this->rows += $num_rows;
}

function add_cols($num_cols) {
        for ($row = 1; $row <= $this->rows; $row++) {
                for ($col = 1; $col <= $num_cols; $col++) {
                        $this->cell[$row][$col+$this->cols] = $this->cell_init();
                }
        }
        $this->cols += $num_cols;
}

function code() {
        if (!empty($this->html)) return 1;
        $this->html = '<TABLE '.$this->table_style.'>'."\n";
        for ($row = 1; $row <= $this->rows; $row++) {
                $this->html .= '<TR>'."\n";
                for ($col = 1; $col <= $this->cols; $col++) {
                        $extra = '';
                        //check if "colspan" defined. if so then hide cells that get merged.
                        if (isset($this->cell[$row][$col]['colspan'])) {
                                $extra .= 'COLSPAN="'.$this->cell[$row][$col]['colspan'].'"';
                                for ($hidden_col = 1; $hidden_col < $this->cell[$row][$col]['colspan']; $hidden_col++) {
                                        $this->cell[$row][$col+$hidden_col]["hide"] = true;
                                        //check if "rowspan" defined. if so then propogate "colspan" into merged rows.
                                        if (isset($this->cell[$row][$col]["rowspan"])) {
                                                for ($hidden_row = 1; $hidden_row < $this->cell[$row][$col]['rowspan']; $hidden_row++) {
                                                        $this->cell[$row+$hidden_row][$col]["colspan"] = $this->cell[$row][$col]['colspan'];
                                                }
                                        }                                        
                                }
                        }
                        //check if "rowspan" defined. if so then hide cells that get merged.
                        if (isset($this->cell[$row][$col]["rowspan"])) {
                                $extra .= 'ROWSPAN="'.$this->cell[$row][$col]['rowspan'].'"';
                                for ($hidden_row = 1; $hidden_row < $this->cell[$row][$col]['rowspan']; $hidden_row++) {
                                        $this->cell[$row+$hidden_row][$col]["hide"] = true;
                                }
                        }
                        // code to draw cell html...
                        if (isset($this->cell[$row][$col]['hide'])) continue; // if hide then skip this cell.
                        
                        // otherwise draw cell with style...
                        if (!empty($this->cell[$row][$col]['cell_style']))
                                $this->html .= '<TD '.$this->cell[$row][$col]['cell_style'].' '.$extra.'>';
                        else
                                $this->html .= '<TD '.$this->cell_style.' '.$extra.'>';
                                
                        // draw content of cell with style...
                        if (!empty($this->cell[$row][$col]['style'])) $this->html .= '<SPAN STYLE="'.$this->cell[$row][$col]['style'].'">';
                        else if (!empty($this->content_style)) $this->html .= '<SPAN STYLE="'.$this->content_style.'">';
                        
                        $this->html .= $this->cell[$row][$col]['content'];
                        
                        if (!empty($this->cell[$row][$col]['style']) or !empty($this->content_style)) $this->html .= '</SPAN>';
                        
                        $this->html .= '</TD>'."\n";
                        
                }
                $this->html .= '</TR>'."\n";
        }
        $this->html .= '</TABLE>'."\n";
}

function display() {
        print $this->html;
}

}

/*
example below...
*/

$data = new html_table;

// define table size.
$data->init(array("cols"=>3, "rows"=>"3"));

// default styles.
$data->table_style = 'BORDER="1" CELLPADDING="2" CELLSPACING="2"';
$data->cell_style = 'WIDTH="100" ALIGN="center" BGCOLOR="white"';
$data->content_style = 'font: bold 9pt monospace;';

// define table content.
$data->cell[1][1]["content"]="apple";
$data->cell[2][2]["content"]="orange";
$data->cell[2][3]["content"]="pear";
$data->cell[3][1]["content"]="plum";
$data->cell[2][1]["content"]="grape";
$data->cell[1][1]["colspan"]=3;
$data->cell[2][3]["rowspan"]=2;
$data->cell[3][1]["colspan"]=2;

// define fancy styles for individual cells.
$data->cell[2][2]["style"] ='font: 18pt monospace;';
$data->cell[2][3]["style"] ='background: red';
$data->cell[1][1]["style"] ='color: red; font: italic 18pt sans-serif;';
$data->cell[3][1]["style"] ='color: white; font: bold 18pt serif;';
$data->cell[1][1]["cell_style"] = 'CLASS="header"';
$data->cell[3][1]["cell_style"] = 'ALIGN="right" bgcolor="blue"';

// code and display.
$data->code();
$data->display();
?>
</body>
</html>



class formHTML build your HTML Forms from PHP
Categories : PHP, PHP Classes, HTML and PHP, HTML
A simple class with some HTML output functions that would come in handy for consistent page layout etc.
Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation
phpFormGenerator for Dynamic Form Generation from MySQL
Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP
GonxTabs : Create elegant HTML tabs based interface
Categories : Navigation, HTML, HTML and PHP, PHP
Popup Menu 0.5, popup, select, html, state-maintaing
Categories : HTML, PHP, HTML and PHP
Class to build a select tag in html, useful to build select boxes from a data base
Categories : PHP, HTML and PHP, PHP Classes
Display Slashdot headers on your own site
Categories : HTML and PHP, HTML, PHP
Form is a utility class for generating html forms. It provides form initialization and regex based data validation (both server and client side) with a convenient interface. This version obsoletes version 1.0a
Categories : HTML, PHP, PHP Classes, Regexps
How to use regular expressions to get the list of links from an HTML page
Categories : PHP, Regexps, HTML, HTML and PHP
CachedFastTemplate class, extends CDI's FastTemplate to allow page caching
Categories : HTML and PHP, HTML, PHP Classes
How to preset a text string in a textarea input field
Categories : HTML, HTML and PHP, PHP, Beginner Guides
Vote-Poll script that has a wrapper class that allows the user to create multiple polls on the same page with little trouble.
Categories : PHP, PHP Classes, HTML and PHP
A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP
PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel