{"id":1375,"date":"2018-01-19T19:22:46","date_gmt":"2018-01-19T19:22:46","guid":{"rendered":"http:\/\/goofy-trucks.flywheelsites.com\/php-and-classes-page-4\/"},"modified":"2018-01-19T19:24:44","modified_gmt":"2018-01-19T19:24:44","slug":"php-and-classes-page-4","status":"publish","type":"post","link":"https:\/\/phpbuilder.com\/php-and-classes-page-4\/","title":{"rendered":"PHP and Classes Page 4"},"content":{"rendered":"<div class=\"phpbuilder-content\">\n<div class=\"phpbuilder-meta\">\n<div class=\"\">By Rod Kreisler<\/div>\n<div class=\"\">on July 30, 2000<\/div>\n<\/p><\/div>\n<div id=\"overflow-content\">\n<div class=\"articlePara\">\nThis function will take a message passed in the argument and print it<br \/>\nout in the appropriate style object.  So to print a message we can:<\/div>\n<div class=\"articlePhpEx\">\n<font face=\"courier\"><code><span style=\"color: #000000\"><\/p>\n<p><span style=\"color: #0000BB\">&lt;?php<\/p>\n<p>$Basic<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">TextOut<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'This\u00a0is\u00a0my\u00a0test\u00a0message'<\/span><span style=\"color: #007700\">);<br \/>\n<br \/><\/span><span style=\"color: #0000BB\">$Tbody<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">TextOut<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'\u00a0--\u00a0kinda\u00a0neat,\u00a0huh?'<\/span><span style=\"color: #007700\">);<\/p>\n<p><\/span><span style=\"color: #0000BB\">?&gt;<br \/>\n<br \/><\/span><br \/>\n<\/span><br \/>\n<\/code><\/font><\/div>\n<div class=\"articlePara\">\nNotice, there are no &lt;BR&gt; between the two function calls so they will<br \/>\nprint on the same line.  Also, I just wanted a smaller font for the<br \/>\nsecond part of the output and I had already declared that in $Tbody so I<br \/>\nused that.  This is safe in this instance as the only other difference<br \/>\nbetween $Basic and $Tbody is &#8220;bgcol&#8221; and that isn&#8217;t used in this<br \/>\nfunction.  Notice the &#8220;&amp;nbsp;&#8221; in the function declaration?  That is<br \/>\nthere so if no message is passed the function will print out a non-<br \/>\nbreaking space.  Why will become clear later on.<\/div>\n<div class=\"articlePara\">\nSo far we haven&#8217;t saved a lot of work.  The last example is easier if<br \/>\nyou want to change font color and\/or size in the middle of a sentence<br \/>\nbut still doesn&#8217;t justify writing an entire class.  How about we add to<br \/>\nthe functions:<\/div>\n<div class=\"articlePhpEx\">\n<font face=\"courier\"><code><span style=\"color: #000000\"><\/p>\n<p><span style=\"color: #0000BB\">&lt;?php<\/p>\n<p><\/span><span style=\"color: #007700\">function\u00a0<\/span><span style=\"color: #0000BB\">TDOut\u00a0<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$message<\/span><span style=\"color: #007700\">=<\/span><span style=\"color: #DD0000\">\"&amp;nbsp;\"<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">$colspan<\/span><span style=\"color: #007700\">=<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">)\u00a0{<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0PRINT\u00a0<\/span><span style=\"color: #DD0000\">\"&lt;TD\u00a0COLSPAN=$colspan\u00a0BGCOLOR=\"$this-&gt;bgcol\"\u00a0\"<\/span><span style=\"color: #007700\">.<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #DD0000\">\"ALIGN=\"$this-&gt;align\"\u00a0VALIGN=\"$this-&gt;valign\"&gt;\"<\/span><span style=\"color: #007700\">;<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">TextOut<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$message<\/span><span style=\"color: #007700\">);<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0PRINT\u00a0<\/span><span style=\"color: #DD0000\">\"&lt;\/TD&gt;n\"<\/span><span style=\"color: #007700\">;<\/p>\n<p>}<\/p>\n<p><\/span><span style=\"color: #0000BB\">?&gt;<br \/>\n<br \/><\/span><br \/>\n<\/span><br \/>\n<\/code><\/font><\/div>\n<div class=\"articlePara\">\nNow, we&#8217;re getting somewhere!  Remember, I wanted to have different<br \/>\nbackground colors for my tables.  Now I can do this:<\/div>\n<div class=\"articlePhpEx\">\n<font face=\"courier\"><code><span style=\"color: #000000\"><br \/>\n&lt;TABLE&gt;<br \/>\n<br \/>&lt;TR&gt;<br \/>\n<br \/><span style=\"color: #0000BB\">&lt;?php<\/p>\n<p>$Theader<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">TDOut<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"Name\"<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">2<\/span><span style=\"color: #007700\">);<br \/>\n<br \/><\/span><span style=\"color: #0000BB\">$Theader<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">TDOut<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"Location\"<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">3<\/span><span style=\"color: #007700\">);<\/p>\n<p><\/span><span style=\"color: #0000BB\">?&gt;<br \/>\n<br \/><\/span>&lt;\/TR&gt;<br \/>\n<br \/>&lt;tr&gt;<br \/>\n<br \/><span style=\"color: #0000BB\">&lt;?php<\/p>\n<p>$Theader<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">TDOut<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"Last\"<\/span><span style=\"color: #007700\">);<br \/>\n<br \/><\/span><span style=\"color: #0000BB\">$Theader<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">TDOut<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"First\"<\/span><span style=\"color: #007700\">);<br \/>\n<br \/><\/span><span style=\"color: #0000BB\">$Theader<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">TDOut<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"City\"<\/span><span style=\"color: #007700\">);<br \/>\n<br \/><\/span><span style=\"color: #0000BB\">$Theader<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">TDOut<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"State\/Province\"<\/span><span style=\"color: #007700\">);<br \/>\n<br \/><\/span><span style=\"color: #0000BB\">$Theader<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">TDOut<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"Country\"<\/span><span style=\"color: #007700\">);<\/p>\n<p><\/span><span style=\"color: #0000BB\">?&gt;<br \/>\n<br \/><\/span>&lt;\/tr&gt;<br \/>\n<br \/><\/span><br \/>\n<\/code><\/font><\/div>\n<div class=\"articlePara\">\nThere.  See how the colspan argument works.  If it&#8217;s not declared it<br \/>\ndefaults to 1.  So in the first table row &#8220;Name&#8221; spans 2 columns and<br \/>\n&#8220;Location&#8221; spans 3.  In the second row all of them cover a single<br \/>\ncolumn.<\/div>\n<\/div>\n<p><\/p>\n<div style=\"float: left; padding:15px; color:#17AAF3\">\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"rod199906019ba9.html?page=3\">\u00ab Previous Page<\/a><\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"rod19990601.html\">1<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"rod199906014658.html?page=2\">2<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"rod199906019ba9.html?page=3\">3<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"background-color:#B6E5FC; font-size:16px; margin-top:1px; padding:1px 4px 1px 4px; color:#000; font-style:bold; float:left;\">4<\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"rod19990601af4d.html?page=5\">5<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"rod19990601c575.html?page=6\">6<\/a> <\/div>\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"rod19990601af4d.html?page=5\">Next Page \u00bb<\/a><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The hardest concept I&#8217;ve tried to understand since beginning to use PHP was that of classes. I&#8217;d never used a database engine but learning to use<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1375","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/comments?post=1375"}],"version-history":[{"count":1,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1375\/revisions"}],"predecessor-version":[{"id":3250,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1375\/revisions\/3250"}],"wp:attachment":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/media?parent=1375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/categories?post=1375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/tags?post=1375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}