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.
Read More