Reading Your Blog
|Figure 9. HTML Template: This is the HTML template for retrieving the BLOG data.|
No blog is any good without the facility to read it! The final page that you will build is a page that takes a parameter for the category, downloads the entire blog for that category, and renders it in HTML for your readers. The best way to start is to mock up how you would want the HTML to appear in an application such as Dreamweaver or FrontPage, and build from there. Figure 9
shows the template for this page, which is available in the download
This template is very straightforward, as it has HTML that uses the standard tags for formatting the text fonts. The page in Figure 9
was built using the following HTML
In a similar way to what you did for creating the form earlier, you can now use this code to form the basis of the getblog.php
file that your readers will use to access your blogs. The format will be http://webserver/getblog.php?category=1
This address includes the desired category number, passed as a parameter
, which is called a GET parameter. There are two types of HTML parameters: GET parameters, which are passed in the address line as above, and POST parameters, which are part of a form submission. PHP gives you the handy $_GET
variables to give you access to these.
The PHP that gets this parameter and uses it to query the database, generating HTML from the returned results, is shown below.
$Category = $_GET['Category'];
$dbconn = @mysql_connect('localhost', 'root', 'rootp');
die('Error connecting to DB!');
if (! @mysql_select_db('blog') )
die( '<p>Unable to locate the main ' .
'database at this time.</p>' );
$SQL = "Select * from `blogs` where Category = " . $Category . "
ORDER BY ID DESC";
while ($row = mysql_fetch_array($result))
You can then build navigation to these pages using (for example) a frameset that links to different URLs where the 'Category=' parameter is set differently. Or if you want to be a little more fancy you can use PHP to generate a page containing these URLs automatically.
Blogs Are Just the Beginning
This article showed you how straightforward and easy it is to build a powerful Web application environment complete with database using the Uniform Server open source project. The site that you build is easily transferable to a live server, hosted by an ISP that supports Apache, PHP, and MySQL, which most do. It's a great way of entering a difficult arena, and a great way to get straight at what you want to dobuild applications! The example application, a Web-based blog application, is just one way to get started with your Uniform Server WAMP development. It has given you the grounding to build just about anything!