RSS Generator

Avatar of Chris Coyier
Chris Coyier on

You’ll need a MySQL database with a a table called `rss_feed`. In that table there are 3 colums: item title (which is the name a person will see for an item), the item link (which is the location of the page with the item on it), and description (which tells what the feed is about). Put the file in a folder called feed and you’re feed will be available at yoursite.com/feed

Remember to change the feed title, link and image for your specific feed.

<?php
   
   // Connect to database... (you'll need to create this yourself)
   require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/connection.php';

   // Run query...
   $getFeed = mysql_query("SELECT *
                           FROM `rss_feed`
                           ORDER BY `time` DESC
                           ")or die(mysql_error());

   // Output XML (RSS)
    echo '<?xml version="1.0" encoding="ISO-8859-1" ?>
          <rss version="2.0">
                <channel>
                        <title>Your RSS Title</title>
                        <link>http://the_location_of_your_feed/feed</link>
                        <description>Description of your Feed</description>
                        <language>English</language>
                        <image>
                                <title>website Logo</title>
                                <url></url>
                                <link>Link to image</link>
                                <width>width</width>
                                <height>height</height>
                        </image>';
						while($rssFeed = mysql_fetch_array($getFeed)) {
        					 echo '<item>',
					              '<title>', $rssFeed['item_title']</title>',
					              '<link>', $rssFeed['link'], '</link>',
					              '<description><![CDATA[ ,$rssFeed['description'],']]></description>
								   </item>';

 						}
				echo '</channel>
        </rss>';

?>