How to Create A Dynamic Rss Feed

6 years ago

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:


//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");
'<?xml version="1.0" encoding="utf-8" standalone="yes" ?>'."
<rss version='2.0'>
<title>Website Feed</title>
<description>Dynamic Website Rss Feed</description>
$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))
' <item><title>'.$row["title"]. '</title>
<pubDate>date of article</pubDate></item>'
?> ?>

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

Related forums

Akeredolu Promises To Create More Local Govts If Reelected

2 months ago

Microsoft launches Expressive Pixels app to help you create animations

2 months ago

Chadwick Boseman’s High School To Create Scholarship In His Honor

3 months ago

6 Factors that create an instant attraction between two people

3 months ago