Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Get AMPed over Uniform Server and Build a Data-driven Web Site in Nothing Flat : Page 4

Web development gets easier all the time, but Uniform Server, an open source project that packs up the ease and power of the 'AMP' platform, takes simplicity to the edge of embarrassing. Go from zero to Web hero in minutes by using our sample blog project to teach yourself the ease and power of AMP.


advertisement
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

<h1>My Headline</h1> <p>My text</p> <hr> <h1>My Headline</h1> <p>My text</p> <hr>

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 and $_POST 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.

<?php $Category = $_GET['Category']; $dbconn = @mysql_connect('localhost', 'root', 'rootp'); if (!$dbconn) { 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"; $result=@mysql_query($SQL); while ($row = mysql_fetch_array($result)) { ?> <h1><?php echo($row['Headline']);?></h1> <p><?php echo($row['Body']);?></p> <hr> <? } ?>

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 do—build 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!



Laurence Moroney is a freelance enterprise architect who specializes in designing and implementing service-oriented applications and environments using .NET, J2EE, or (preferably) both. He has authored books on .NET and Web services security, and more than 30 professional articles. A former Wall Street architect, and security analyst, he also dabbles in journalism, reporting for professional sports. You can find his blog at http://www.philotic.com/blog.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap