DEVELOPMENT

RSS - Really Simple Syndication, is use to supply news feed, new blog post or other data where the information is timely updated. These timely feeds are distributed as channel by their respected publishers. Subscribing the rss feed involve the step of getting the link of rss feed provided by the website and copying that into rss reader. Rss basically implements the notification system.

rss screenshot

THE SITUATION

We have a database with some entries in it. Using these entries, an rss feed(or .rss file) is to be generated with a given title, description and link. However, the entries of database can be later changed for producing new feeds.

THE TABLE

database

Our table consist of four coloumns. I've arbitrary stored two entries in the database.

database screenshot

Now, we have to create a rss document by using these value. Here, i'm using php to perform the task.

INDEX.PHP
header('Content-type: text/xml');
echo "<?xml version='1.0' encoding='UTF-8'?>";
echo '<rss version="2.0">';
echo '<channel>';
echo '<title>News</title>';
echo '<link>http://url</link>';
echo '<description>http://url</description>';
echo '<language>http://url</language>';

$conn=@mysql_connect("localhost","root","") or die("could not connect to database");
$db=@mysql_select_db("blog",$conn) or die("could not select database");
$result = mysql_query("SELECT * FROM rss",$conn);
$num=mysql_numrows($result);
$i=0;

while($i<$num)
{
 $tit=mysql_result($result,$i,"tit");
 $link=mysql_result($result,$i,"link");
 $des=mysql_result($result,$i,"des");
 echo '<item>';
 echo "<title>$tit</title>";
 echo "<link>$link</link>";
 echo "<description>$des</description>";
 echo '</item>';
 $i++;
 
}

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


Leave a Comment  
Download Code(39)





All rights reserved, the content is copyrighted to the author.

RELATED POST