(5 ratings)   
By: arkinex.com
This tutorial will teach you how to create a simple RSS 2.0 compliant feed from a MySQL (or others with a few small changes) database.
Added: 23 June 2008    Views: 776  
PathComputers    Programming    Php
Keywords: computers   programming   php   coder   code   language   rss   mysql  
Do you like this tutorial? Now you can support our team to add more :     
 
 
 

This tutorial will teach you how to create a simple RSS 2.0 compliant feed from a MySQL (or others with a few small changes) database.

The first thing you must do in a RSS document is to define that it is indeed an RSS feed. We do this like so…

echo '';
echo '';

We then must open the ‘channel’ tag, which is just our feeds main content and then give our feed some information of what it is and where it is from.

echo ''; // Opens our main content
echo ''; // Defines the title of the RSS feed
echo 'http://www.testsite.com'; // Where the RSS feed is from
echo 'This RSS feed is all about the pie.'; // What its about

We then open a MySQL connection and query the server for our information, I have used a database called “test” and a table named “news”. As you can guess, this RSS feed is going to show the latest news from our test website.

$c = mysqli_connect('localhost', 'user', 'pass', 'test') or die(mysqli_error($c));
 // Connect with our information
$q = mysqli_query($c, 'SELECT * FROM news ORDER BY id DESC LIMIT 5') or die(mysqli_error($c));
// Query the table for 5 news articles sorting by 'id'
while($r = mysqli_fetch_assoc($q)) // While there is more rows to get
 (max of 5) we get an associative array

{

Now we want to print out each news article in a RSS compliant manner. All elements (each news article) must have a title, link and description to be RSS compliant. I have added and (published date) also. Note: must be in the RFC 822 standard.

echo ''; // Begin a news article
echo ''; // Give it a title
echo ''.$r['permalink'].''; // The link to the article
echo ''.$r['content'].''; // The description or content of the article
echo ''.$r['author'].''; // The author
echo ''.$r['date'].''; // The date is was published
echo ''; // End news article
} // End while statement

We then finish the document by closing our and tags.

echo '';
echo '';

I hope you enjoyed my first tutorial, please comment if you have any questions.

About the Author :
arkinex.com
RSS Feed from a MySQL Database
Articles and Tutorials Directory by www.learnfobia.com
 Rate this tutorial : Rate 1Rate 2Rate 3Rate 4Rate 5
  |    Add to Favorites
  |    Send to Friend
  |    Print
Comments