|
|
|
This snippet of code can be used to build dynmic tables and format each cell with a defined style.
Its current state is very basic, but you could easily extend it to support much more.
Here is the basic code first, then I will show an example of how to use it.
<style>
.box1 td{
border-right: 1px solid #999;
border-bottom: 1px solid #999;
background: #cc9;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
padding : 0px 2px;
}
.box2 td{
border-right: 1px solid #999;
border-bottom: 1px solid #999;
background: #eed;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
padding : 0px 2px;
}
</style>
<?
class BOX {
var $final;
// start the table
function s($width) {
$this->final = '<table width="'.$width.'" cellpadding="0" cellspacing="0">';
}
// start a new row
function r($content, $style) {
$this->final .= '<tr class="box'.$style.'"><td>'.$content.'</td></tr>';
}
// complete and return the table
function finish() {
return $this->final .= '</table><br />';
}
}
?>
Example:
<?
$tab = new box; // creat new object
$tab->s("135"); // start the table with width of 135
$tab->r("this is my header", 1); // create row with using style 1
$tab->r("this is my sub", 2); // create row using style 2
$tab->r("this is my sub", 2); // create row using style 2
$tab->r("this is my sub", 2); // create row using style 2
$multiline = "this is a multi-line<br/>example."; // create a variable first before adding to new
row
$tab->r($multiline, 2); // add the variable to create new row
echo $tab->finish(); // now print the table to screen
unset($tab); // kill object
?>
|
|
| Class to build a select tag in html, useful to build select boxes from a data base Categories : PHP, HTML and PHP, PHP Classes | | | 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 | | | 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 | | | How To Create a PDF Using PHP Categories : PHP, PDF, PHP Classes, HTML and PHP | | | class formHTML build your HTML Forms from PHP Categories : PHP, PHP Classes, HTML and PHP, HTML | | | Customizable Calendar Class Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar | | | XTemplate, a template class for PHP Categories : PHP Classes, HTML and PHP, 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 | | | 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 | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | | | Authorize.net AIM Interface Class v1.0.0 Categories : PHP, PHP Classes, Ecommerce, Payment Gateways | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | crop and resize image class using gd library function Categories : PHP, PHP Classes, GD image library, Graphics | |
| | | | kenji wrote : 943
I have one question. Could you explain why you would use stylesheets to build a table when the stylesheet could be used to create your page using <div> and <span> tags with greater speed and less code?
| | | | Stuart Cochrane wrote : 944
Well as with everything in programming - people prefer to do things their own way.
This example was designed to show how easy it is to add styles to individual table elements and states that it can easily be extended to fit your own needs.
Thanks for your comments anyway, critism is always good!!
| | | | kenji wrote :957
No worries. A basic table will always be needed in case a user uses their own stylesheets ... for now.
| |
|
|
|