On Wed, June 14, 2006 12:37 pm, Alex Major wrote: > I've been (very slowly) working my way through some basic php, and > putting it into my html site. However recently (after trying things > out such > as cookies or redirects where they have to be set before any page > output) > I've found that the combination or certainly the way that I'm using > php and > html together dosn't seem to go too well. You have stumbled into the (unoriginal, I'm afraid) concept of separating business logic (PHP) from presentation (HTML) There are about a thousand sub-schools of this, including all kinds of acronyms (MVC springs to mind). You COULD spend the rest of your life studying and never write another line of code... There are also a variety of PHP "Template Libraries" (such as Smarty) which more-or-less lead you by the nose (and sometimes force) you to separate your Business Logic (PHP) from your Presentation (HTML). There are also some schools of thought where *SOME* of the PHP is actually NOT really businees logic, but is, in fact, part of the presentation. Consider, for example, the "simple" concept of a date. Ignoring for the moment the various different calendaring systems, and historical re-vampings, and sticking to the most rudimentary representation of Unix timestamp such as that used by http://php.net/date function... It could be argued that, really, the decision to display: 6/15/2006 versus 15-06-2006 versus June 16, 2006, is really not "business logic" per se, but merely a Presentation Detail. So *some* developers prefer that the minutiae of that particular decision not be FORCED to be in the Business Logic by some external library attempting to separate Business Logic and HTML. But, I digress... > I have a question to you experienced PHP developers, how do you mix > the > html/php together. When I've looked at things like the PHPBB forums, > and > gone through files they will have absolutly no HTML, just php code. > I'm not > sure how they manage their page styling, if anyone could explain this > too > me. Errr. I think perhpas phpBB would not be the first place I'd send a newbie to try and figure this out, personally... > At the moment I have things such as > <table ...> > <?php > Some php code making a page header > ?> > </table> > <table ...> > <?php > Content... > ?> > </table> > > I'm sure that I'm not doing it the best possible way, so if anyone has > any > tips for me. I would say that, in general, for a SIMPLE web application, and for a disciplined developer (or one learning to become a disciplined developer) it would be sufficient to do: <?php //bulk of all the "tricky" code here: // big sql queries, working out what to do with user input // error handling ?> <html> <head> <!-- Only html stuff below, with an occasional PHP echo snippet: --> <title><?php echo $title?></title> </head> <body> </body> </html> One implication of this is that all your header() calla, and all the Business Logic to decide what/when to DO your header() calls, goes in the top bit. This then takes care of the problem of stray output making header() calls not work. I can guarantee that somebody on this list is going to be agahst at this recommendation of such a crude solution -- But it has served me well for a decade for SIMPLE WEB APPLICATIONS and is much less effort and more maintainable simply by scale/scope of code-base for SIMPLE WEB APPLICATIONS. If you're attempting to write the next Google or something on that scale, then this *IS* admittedly a horrible idea. For a beginner, however, you'll learn a lot more, a lot faster doing this than trying to stumble through some over-engineered monstrosity template library. Now I'd better really get out my flame-retardant undies. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php