Creating a Dynamic News Feed in PHP

In this article we look at how to create a dynamic news feed. By delivering the content of the feed as JavaScript, it can be incorporated easily into any site, as the feed is gathered by the user's browser and so does not need any special software on the host's server.

We then look at reading records from a MySQL database, putting the results in an array so that the data can be worked with easily later on in our code. We create a custom function to display a number of characters from a string, without splitting the string in the middle of a word. By making the number of characters to display a parameter of the function, we made it general- purpose, so that it can be used easily on other sites to save time in the future. We then look at displaying the news data using JavaScript.

Finally, we create a page that read a parameter from the pages URL, and uses it to select a record from the database, and we display this data on the page, so that a visitor can read the whole of their selected news item.

$2.79
- OR -

Overview

Table of Content:

  • Creating a Dynamic News Feed in PHP
  • Why provide a content feed
  • How the feed works
  • Setting up the MySQL Database
  • Creating the Feed
    • Reading the News item from the Database
    • Creating a function to show a set number of Characters from a field
    • Adding the Main Code
  • How to Add the Feed to a Site
    • CSS (Cascading Style Sheets)
  • Creating a Page that displays a News Item 

Gareth Downes-Powell

Gareth Downes-PowellGareth has a range of skills, covering many computer and internet related subjects. He is proficient in many different languages including ASP and PHP, and is responsible for the setup and maintenance of both Windows and Linux servers on a daily basis.


In his daily web development work he uses the complete range of Macromedia software, including Dreamweaver MX, Flash MX, Fireworks MX and Director to build a number of websites and applications. Gareth has a close relationship with Macromedia, and as a member of Team Macromedia Dreamweaver, he has worked closely in the development of Dreamweaver, and was a beta tester for Dreamweaver MX.


On a daily basis he provides support for users in the Macromedia forums, answering questions and providing help on a range of different web related subjects. He has also written a number of free and commercial extensions for Dreamweaver MX, to further extend its capabilities using its native JavaScript API’s or C++.


As a web host, Gareth has worked with a range of different servers and operating systems, with the Linux OS as his personal favourite. Most of his development work is done using a combination of Linux, Apache and MySQL and he has written extensively about setting up this type of system, and also running Apache and MySQL under Windows.

See All Postings From Gareth Downes-Powell >>

Reviews

Well-Written

February 2, 2005 by Joe Sweeney
I have been programming for over 20 years, and teaching for over 6. Gareth explains each step very clearly. This is the first PHP article I've read that's been easy to understand. Most I've read have been very cryptic.

You must me logged in to write a review.