Demonstrates how to create an RSS feed using PHP/MySQL
<?php // the query to get your different items for the RSS feed $query = "select link, title, description from `news` limit 15"; $dbconnect = mysql_connect('localhost', 'dbuser', 'dbpassword'); mysql_select_db('dbname', $dbconnect); // we will use $result on line 30 $result = mysql_query($query, $dbconnect); @header("Content-Type: application/rss+xml"); echo '<?xml version="1.0" encoding="utf-8"?>'; ?> <rss version="2.0"> <channel> <title>Title of your Feed</title> <link>http://mysite.com/</link> <description>This is just a feed for my blah blah blah.</description> <language>en-us</language> <pubDate><?php echo date("D, d M Y H:i:s T"); ?></pubDate> <lastBuildDate><?php echo date("D, d M Y H:i:s T"); ?></lastBuildDate> <docs>http://mysite.com/rssfeed.link</docs> <generator>PHPSnaps Simple RSS Feed</generator> <managingEditor>editor@mysite.com</managingEditor> <webMaster>webmaster@mysite.com</webMaster> <?php while ($row = mysql_fetch_assoc($result)) { echo "<item>"; echo " <title>" . htmlentities($row['title']) . "</title>"; echo " <link>" . htmlentities($row['link']) . "</link>"; echo " <description>" . htmlentities($row['description']) . "</description>"; echo "</item>"; } ?> </channel> </rss>
You will need to edit this to fit your needs, but it shows how simple it is to create an RSS feed using PHP and MySQL. Change the query to go along with your news/blog table, and edit the XML parts to accurately go with your webpage. If you alter the query structure be sure to check the while loop that starts on line 30. < link > should point to the webpage that particular news entry can be located.
Comments
guest
Posted on 19.03.2011 20:48
it doesnt work u wanker
Add your comment