Re: Using PHP/HTML effectivly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 1:28 PM -0700 6/14/06, BBC wrote:
>I used many functions as template to change the html syntax.
>this is one of the function as a sample:
><?php
>function tabletag($border="0",$width="100%",$height="100%",$cellpadding = "0",$cellspacing="0",$style="")
>{
> print ("<table width=\"$width\" height =\"$height\" border=\"$border\" cellspacing=\"$cellspacing\" cellpadding=\"$cellpadding\" style=\"$style\">");
>}
>?>
>so I don't need to type "<table ....>", just call those functions.
>and I don't think it works slowly (cause we just set one function for many tables)

BBC:

Personally, I see what you are trying to do, but I would not be going that route.

Like many others, I don't work in a shop where one group does php and another does the designing and such -- I'm just a one man band who has to do it all and make it work.

For me, I use php/mysql, html, js, and css all together to do stuff -- but, I try to keep them as separate as I can.

CSS helps a LOT because I can use simple html tags like:

<table>
...
</table>

And put the presentation code for the table in css. CSS seldom mixes with php and it helps reduce the amount of code I have to review. Plus, css separates "look" from performance (i.e., php/js/html) -- I can change one without worrying about the other.

Typically, the amount of html code I have is far less than php. I often roll html code segments (like header and footer) into php includes and keep them tucked away so I don't have to look at anything except:

include(header.inc);

Now, there is html code that I have to "mix" into my php and I usually separate it by using the method you first suggested, such as:

<?php
... bunches of php code
?>

bunches of html code

<?php
... bunches more of php code
?>

To me, that's easy to read and I have no problem mixing stuff that way.

Occasionally, I have to "intermix" html and php together in the same statement such as filling text field from a dB, such as:

<input type="text" size="7" maxlength = "7" name="price" value="<?php echo($price); ?>">

But, it's pretty clear that I'm using php to set what the value is in an html statement.

Even fewer times, but I still do, I intermix css, js, html, and php all together, such as:

<td class="search_btn">
<input type="button" value="Album" onclick="window.location='search.php?unique_id=<?php echo($unique_id);?>' ">
</td>

But still, I think it's pretty clear what I'm doing. CSS takes care of how the button looks; js takes care of what happens when the user clicks; php provides something from the dB; and html is the glue that holds everything together. They all work in concert.

One of the things I keep in mind is when I start using a lot of escape characters (as you did above), then I'm not doing it the "best way" (IMO) and I look for another solution.

I would much rather see code

?>
<table>
...
</table>
<?php

Than to intermix it as you did.

Now, purest would like all languages to be separate and I can't argue with that -- however -- if this is what it takes to get the job done, then what choice do you have?  I look at it all like it's one big language and that works for me -- others mileage may vary.

hth's

tedd

-- 
------------------------------------------------------------------------------------
http://sperling.com  http://ancientstones.com  http://earthstones.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux