Creating a Custom RSS Feed with PHP and MySQL

By Kris Hadlock


Application Security Testing: An Integral Part of DevOps

The RSS class constructor is a public method that requires the mysql_connect.php file. Remember to put this file in a safe location on your server so it's not exposed to hackers. Once the file's in place change the path in the RSS constructor. The next method in the RSS class is GetFeed, which is a public method that we're calling from the index. This method will concatenate the details and items and return a valid RSS 2.0 structure. The first method it calls is a private method called getDetails. This method makes a connection to our webref_rss_details table and selects all of the values. Once the results are retreived the RSS file is constructed from the database data in a while loop that iterates the rows in the database. Once complete the getDetails method returns the details for the RSS structure.

The second method that GetFeed calls is a private method called getItems. This method selects all of the values in the webref_rss_items table and iterates them. While iterating the values a string of XML is constructed that represents the item structure for the RSS file. Once complete the getItems method returns the item structure to the GetFeed method, which in turn returns the entire RSS structure to the index to be written to the page.


This code sample is a good start for a complex custom RSS feed creator. We could easily create a form that adds or updates new items in our database. For now I give you the base because I'm sure you have many ideas of your own. Armed with this new RSS file you can go to a Web site such as FeedBurner to make it easier to deliver your content to the public.

About the Author

Kris Hadlock is the co-founder of 33Inc alongside Robert Hoekman. He is the author of Ajax for Web Application Developers and has been a feature writer for numerous Web sites and design magazines. To learn more about Kris, visit his Web site at http://www.krishadlock.com or his blog at http://www.krishadlock.com/blog

This article originally appeared on WebReference.com.

Page 2 of 2

Previous Page
1 2

Make a Comment

Loading Comments...

  • Web Development Newsletter Signup

    Invalid email
    You have successfuly registered to our newsletter.

    By submitting your information, you agree that htmlgoodies.com may send you HTMLGOODIES offers via email, phone and text message, as well as email offers about other products and services that HTMLGOODIES believes may be of interest to you. HTMLGOODIES will process your information in accordance with the Quinstreet Privacy Policy.

Thanks for your registration, follow us on our social networks to keep up-to-date