|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
学习数据库了,MYSQL可算是PHP的黄金搭档了,不过,虽然话是这么说,你也可能恨不得把MYSQL给生吞活剥了,因为这一行一列的东东简直让自己头晕目眩。 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 isn't 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 haven't 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 doesn't 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, we're 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 it's 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.
不断巩固,摸透大部分PHP常用函数,并可理解OOP,MYSQL优化,以及模板 |
|