HomePHP Page 4 - Building A Quick-And-Dirty PHP/MySQL Publishing System
Bedtime Stories - PHP
Looking to quickly add a dynamic news page to your corporate orpersonal Web site? This article shows you how, combining PHP's rapidapplication development capabilities with a MySQL database to create aprimitive news publishing system and administration module in just underfour hours.
You'll see, from the code on the previous page, that every press release title is linked to a script named "story.php" via its unique ID. This "story.php" script displays the complete text for the selected press release - and it looks like this:
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to
// select database
mysql_select_db($db) or die ("Unable to select database!");
// generate and execute query
$query = "SELECT slug, content, contact, timestamp FROM news WHERE id =
$result = mysql_query($query) or die ("Error in query: $query. " .
// get resultset as object
$row = mysql_fetch_object($result);
// print details
<b><? echo $row->slug; ?></b>
<font size="-1"><? echo nl2br($row->content); ?></font>
<font size="-2">This press release was published on <? echo
formatDate($row->timestamp); ?>. For more information, please contact <?
echo $row->contact; ?></font>
<font size="-1">That press release could not be located in our
// close database connection
<!-- page footer - snip -->
Again, extremely simple - connect, use the ID to get the full
text for the corresponding item, and display it. Here's what it looks like:
With that, I've successfully completed the first part of this development effort. I now have a primitive publishing system that can be used to provide users of a Web site with news, press releases and other information.