. Creating a Custom RSS Feed with PHP and MySQL - WebReference.com-

spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / authoring / languages / xml / rss / custom_feeds / 1 To page 1current page
[previous]

Sr. Business Analyst, JAD, UAT
Aquent
US-WI-Milwaukee

Justtechjobs.com Post A Job | Post A Resume
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Creating a Custom RSS Feed with PHP and MySQL

The mysql_connect.php file defines our database connection information, makes the initial connection and selects the defined database.

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.

Conclusion

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

home / authoring / languages / xml / rss / custom_feeds / 1 To page 1current page
[previous]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Working with the DOM Stylesheets Collection · Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Combine BottomCount() with Other MDX Functions to Add Sophistication · Creating a Daemon with Python · The Coming Voice-over-WiMAX Revolution

Created: March 27, 2003
Revised: November 1, 2006

URL: http://webreference.com/authoring/languages/xml/rss/custom_feeds/1