Advanced PHP for Beginners

Table Class

Allows you to see (and edit) in an instant your html table by separating the content from the markup.

Download Now!
Table ( [ $vars ] )
row ( [ $align [, $bgcolor ]] )
cell ( [ $vars [, $content ]] )
close ( )
An Advanced PHP for Beginners Example
The (X)HTML Output
Final Result
object Table ( [ string $vars ] )top

Creates an (X)HTML table object.

$vars:
A "|" delimited string of table attributes and their values. No quotes needed.
Example:
<?php

$tb 
= new Table ('class=center|cellpadding=5');

?>
string row ( [ string $align [, string $bgcolor ]] )top

Creates a new row in your table.

$align:
Either 'left', 'center', or 'right' to align all of the cells in this row at once.
$bgcolor:
A color's name or hexidecimal value to set the background color of this row.
Returns:
A string of code to add to your $html.
Example:
<?php

$html 
.= $tb->row('center');

?>
string cell ( [ string $vars [, string $content ]] )top

Creates a new cell within your $tb->row().

$vars:
A "|" delimited string of cell attributes and their values.
$content:
The cells content. It looks nicer here, but any content added to your $html before you start a new row or close the table will show up in this cell.
Returns:
A string of code to add to your $html.
Example:
<?php

$html 
.= $tb->cell('valign=top''This cells content');

?>
string close ( )top

Ties up the loose ends, and closes out the table.

Returns:
A string of code to add to your $html.
Example:
<?php

$html 
.= $tb->close();

?>
An Advanced PHP for Beginners Example:top
<?php

$page 
= new Page;
$page->link('style.css');
$html '';

$tb = new Table ('width=500|cellpadding=5|border=1');
$html .= $tb->row();
$html .= $tb->cell('align=left''Cell 1');
$html .= $tb->cell('align=center''Cell 2');
$html .= $tb->cell('align=right''Cell 3');
$html .= $tb->row('center');
$html .= $tb->cell('rowspan=2''All Cells Centered');
$html .= $tb->cell('colspan=2''In This Row');
$html .= $tb->row('''#FFCC00');
$html .= $tb->cell('colspan=2''New Row');
$html .= $tb->row();
$html .= $tb->cell('colspan=3|align=right''Notice how easy it is to see what is going on?');
  
$t1 = new Table ('align=left|border=1');
  
$html .= $t1->row();
  
$html .= $t1->cell('colspan=3''Easy as . . .');
  
$html .= $t1->row();
  
$html .= $t1->cell(''1);
  
$html .= $t1->cell(''2);
  
$html .= $t1->cell(''3);
  
$html .= $t1->row();
  
$html .= $t1->cell('colspan=3'' . . . or pie!');
  
$html .= $t1->close();
  unset (
$t1);
$html .= '<br /><br />Think outside of the bun.';
$html .= $tb->close();
unset (
$tb);

echo 
$page->display ($html);

?>
The (X)HTML Output:top
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>Advanced PHP for Beginners</title>
  <meta name="description" content="Advanced PHP for Beginners">
  <meta name="keywords" content="Advanced PHP for Beginners">
  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
  <link rel="stylesheet" type="text/css" href="http://www.advancedphpforbeginners.com/combine/style.css">
</head>
<body>
  
  <table width="500" cellpadding="5" border="1">
  <tr>
  <td align="left">Cell 1</td>
  <td align="center">Cell 2</td>
  <td align="right">Cell 3</td></tr>
  <tr>
  <td rowspan="2" align="center">All Cells Centered</td>
  <td colspan="2" align="center">In This Row</td></tr>
  <tr bgcolor="#FFCC00">
  <td colspan="2">New Row</td></tr>
  <tr>
  <td colspan="3" align="right">Notice how easy it is to see what is going on?
    <table align="left" border="1">
    <tr>
    <td colspan="3">Easy as . . .</td></tr>
    <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td></tr>
    <tr>
    <td colspan="3"> . . . or pie!</td></tr>
    </table><br><br>Think outside of the bun.</td></tr>
  </table>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        </body>
</html>
Final Result:top
Bookmark This Page
Home
Download
Contact Us