How to Create A Dynamic Rss Feed

Forum 9 years ago

How to Create A Dynamic Rss Feed

Hello everyone!
I want to share a piece of code, 'few' or 'most' people usually have issues creating--->A dynamic rss feed.
Dynamic means-- fetching articles from the database.
Instead of you updating the rss manually.
Like a month back, some guy was here having issues with it, I don't know if I helped with his issue, because I never really ran the codes on my machine.
Until one day I decided to try, and I discovered why he had issues.
Now I'll be using Mysqli queries first,
Then I'll put up the Mysql query syntax for those still using mysql in a comment(//) below the mysqli syntax.
Ok to cut the story story...
Here's the code.

PHP Code:


<?php 

<?php
//first include your database connection //setup
//lets call it include_database.php
Include 'include_database.php';

//now let's set the header content to xml
//because we won't be saving the file with
 //the extension .xml instead it will be .php
//That is dynamic_rss.php
header("Content-Type: application/xml");
echo 
'<?xml version="1.0" encoding="utf-8" standalone="yes" ?>'."
<rss version='2.0'>
<channel>
<title>Website Feed</title>
<description>Dynamic Website Rss Feed</description>
<link>LinkToWebsiteRss.com</link>"
;
$query "SELECT * FROM `articles` LIMIT 30";
//you can change your limit values!
$result mysqli_query($dbconn$query);
//if u are still using mysql
//do this $result = mysql_query($query)
//remove the 'i' in the mysqli
 
While($row mysqli_fetch_array($result))
{
echo 
' <item><title>'.$row["title"]. '</title>
<description><![CDATA['
.$row["article_story"].']]></description>
<link>http://link_to_the_full_article_story.com</link>
<pubDate>date of article</pubDate></item>'
;
}
echo 
'</channel>';
echo 
'</rss>';
?> ?>


I hope this helps!
Feel free to contact me if you have any issues.
Thank you :)

What's your rating?
0
{{ratingsCount}} Votes


Related forums
That Boy Go Fit Buy And Feed You – Verydarkman Slams Tolanibaj Over Comment About Lord Lamba
Forum | 1 month ago

That Boy Go Fit Buy And Feed You – Verydarkman Slams Tolanibaj Over Comment About Lord Lamba

Bobrisky Vows to Feed 500 Everyday for 30 Days to Mark Ramadan
Forum | 1 month ago

Bobrisky Vows to Feed 500 Everyday for 30 Days to Mark Ramadan

Please Don’t Feed the Children: Giancarlo Esposito Joins Destry Allyn Spielberg’s Thriller Movie
Forum | 4 months ago

Please Don’t Feed the Children: Giancarlo Esposito Joins Destry Allyn Spielberg’s Thriller Movie

When I Die, Feed My Body To My Family To Eat – Phyna Shares Cryptic Post
Forum | 6 months ago

When I Die, Feed My Body To My Family To Eat – Phyna Shares Cryptic Post