DisplayRight, 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:
index.php (create a index page to link to the add and list pages)
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.
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.
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:
No Comments for this page.