Home arrow PHP arrow 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.

TABLE OF CONTENTS:
  1. Building A Quick-And-Dirty PHP/MySQL Publishing System
  2. A Little Slug-gish
  3. A Maniac Is Born
  4. Bedtime Stories
  5. Admin Ahoy!
  6. Splitting Up
  7. Erasing The Past
  8. Changing Things Around
  9. Game Over
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 44
March 12, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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
include("../conf.php");
include("../functions.php");

// 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
$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)
{
?>
<p>
<b><? echo $row->slug; ?></b>
<p>
<font size="-1"><? echo nl2br($row->content); ?></font>
<p>
<font size="-2">This press release was published on <? echo
formatDate($row->timestamp); ?>. For more information, please contact <?
echo $row->contact; ?></font>
<?
}
else
{
?>
<p>
<font size="-1">That press release could not be located in our
database.</font>
<?
}

// close database connection
mysql_close($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.

 
 
>>> More PHP Articles          >>> More By icarus, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: