Logo         Community
The Company
Your Account
Contact Us
Building A Quick-And-Dirty PHP/MySQL Publishing System
Looking to quickly add a dynamic news page to your corporate or personal Web site? This article shows you how.

| Bedtime Stories |

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:

// story.php - display contents of selected press release

<!-- page header - snip -->

// includes

// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

// generate and execute query
$id = mysql_escape_string($_GET['id']);
$query = "SELECT slug, content, contact, timestamp FROM news WHERE id = '$id'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

// get resultset as object
$row = mysql_fetch_object($result);

// print details
if ($row)
<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 database.</font>

// 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:

Output image

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.

How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!

previous page more like this  print this article  next page
In trog...
Logging With PHP
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
Caching Web Sites With PEAR Cache
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
In cut!...
American Chai
The Core
Find out how you can use this article on your own Web site!

Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback