classes and php
this function will take a message passed in the argument and print it out in the appropriate style object. so to print a message we can:
<?php
$basic->textout(this is my test message);
$tbody->textout( — kinda neat, huh?);
?>
notice, there are no <br> between the two function calls so they will print on the same line. also, i just wanted a smaller font for the second part of the output and i had already declared that in $tbody so i used that. this is safe in this instance as the only other difference between $basic and $tbody is "bgcol" and that isnt used in this function. notice the " " in the function declaration? that is there so if no message is passed the function will print out a non- breaking space. why will become clear later on.
so far we havent saved a lot of work. the last example is easier if you want to change font color and/or size in the middle of a sentence but still doesnt justify writing an entire class. how about we add to the functions:
<?php
function tdout ($message=" ",$colspan=1) {
print "<td colspan=$colspan bgcolor=\"$this->bgcol\" ".
"align=\"$this->align\" valign=\"$this->valign\">";
$this->textout($message);
print "</td>\n";
}
?>
now, were getting somewhere! remember, i wanted to have different background colors for my tables. now i can do this:
<table>
<tr>
<?php
$theader->tdout("name",2);
$theader->tdout("location",3);
?>
</tr>
<tr>
<?php
$theader->tdout("last");
$theader->tdout("first");
$theader->tdout("city");
$theader->tdout("state/province");
$theader->tdout("country");
?>
</tr>
there. see how the colspan argument works. if its not declared it defaults to 1. so in the first table row "name" spans 2 columns and "location" spans 3. in the second row all of them cover a single column.