Search
Left Quote    Choose a job you love, and you will never have to work a day in your life.
- Confucius    
Right Quote
 
[login] | [Register]
 

Building a News Management System

by: sm0ke
Page: 4 of 5
(View All)

Display

Right, we now have a system to do the following:

Add, edit and delete news posts from within an admin section on your site. The part to do now, is display the news posts to your users. No point in adding news only to edit and delete it with no one able to see it.

Up till now your dir structure should look like this:

public_html
-----SITE
   site.inc.php

-----ADMIN
   index.php (create a index page to link to the add and list pages)
   add.php
   ed.php
   del.php
   list.php

The site inclusion file (site.inc.php) is sitting in its own directory under the public_html/htdocs/www/ / dir (this varies between servers). As well as calling this into the admin section to login to the database, we will also use the same file in the users section so the scripts to display news posts can also access the database.

First off, we'll create a file called (list.php) under your public html directory.

The list.php file works along the same way as your admin list.php file, but will display the title of the post, the day it was posted and a link to read the article.

list.php:


Pretty straight-forward, yes? The script requests every title in the database and displays it with a link to read the story, the limit on this list can be set by adding "LIMIT 0,x" with x being the max number of posts to display after the "id DESC" part of the query.

the link location "r.php?id=" will redirect to the page r.php and display the story selected from the list.

In the code sample below, we log into the database and collect all the information, then display it.

r.php:


Now, you may notice the inclusion of the 2 commands: nl2br(); and formatDate(); nl2br is a handy php function to convert line terminators to the valid html "<br>" tag. so no added html br tags need to be inserted in your posts.

the formatDate() is a function im going to introduce next to format the date element from an unformatted string to a nicely formatted readbale string.

file: site.funct.php - save in the site directory:




1  |  2  |  3  |  4  |  5  |  
Next »


No Comments for this page.

You Must be logged in or a member to comment.


Tutorial Stats

Tutorial Stats

542,366 Views
6 Total Comments
0 Rating of 5 ( Votes)

Options

Tutorial Options

· Login to Rate This Article
· Login to Post a Comment
· Read more by this author
Digg This Article! Del.icio.us: Bookmark This Article Reddit: Bookmark This Article BlinkList: Blink This Article! YahooMyWeb BlogMarks: Add This Mark! Furl: Save This Article Spurl: Mark This Article

Articles

Related    

· Simple PHP Tutorial
· One File Website
· Pagination with PHP
· Building a Comments Script
· Complete Members System
· Variable Scope



"AllSyntax.com" Copyright © 2002-2017; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank