PostWorlds, Viewing Pages, PHP Classes

I looked at this giant post about to hit Facebook and thought it might be better as a blog post.  I’m working on a Play By Post site in the style of the site I once loved, and spent a while working on how to view a page that had been stored in the database.  There were multiple “hard way”s to write one of the pages.

All of the code here is very simplified from what I’m trying to (except the HTML examples), and the variable names are not the same as in my real code.

The easiest way was to intermingle the programming language and the HTML/web page language at every step of the way.  The PHP scripting and HTML code would be so intermingled that none of it could be easily re-used, or even understood after any time has passed.  I’m not even going to write that here.  It would have been a piece of script to open the database connection and connect to this “row” of data, followed by enough HTML to get to where the next piece of data is needed, followed by PHP script to retrieve that piece of data alone, followed by enough HTML to get to where the next piece of data is needed.  Everything would have been horribly tangled up, and a pure nightmare to look at.  Where I separate my scripting code and my HTML code by creating objects.