I'm just trying to get to grips with OO PHP, and am having trouble with the following very simpl class:
Code: Select all
class create_Table {
var $width;
var $height;
var $border;
var $rows;
var $content;
var $data;
function create_Frame ( ) { // create the framework for the table
echo "<table border = ". $this->border ." width = ". $this->width ."% height = ". $this->height .">\n";
$num = 1;
$rows = $this->rows;
while ( $num <= $rows ) {
echo "<tr><td>". $this->content ."</td><td>Function call: ". $this->add_Data ( ) ."</td></tr>\n";
$num++;
}
echo "</table>\n";
} // end of function create_Frame ( )
function add_Data( ) { // Add some data to the cells calling this function
echo $this->data;
}
} // end of classCode: Select all
$table2 = new create_Table ( );
$table2->data = "Hello world";
$table2->width = "100";
$table2->height = "200";
$table2->border = "2";
$table2->rows = "4";
$table2->content = "Second table";
$table2->create_Frame ( );Code: Select all
<table border = 2 width = 100% height = 200>
Hello world<tr><td>Second table</td><td>Function call: </td></tr>
Hello world<tr><td>Second table</td><td>Function call: </td></tr>
Hello world<tr><td>Second table</td><td>Function call: </td></tr>
Hello world<tr><td>Second table</td><td>Function call: </td></tr>
</table>Thanks in advance...