



(5 ratings)
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
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
echo '';
echo '';
I hope you enjoyed my first tutorial, please comment if you have any questions.
20 Random Tutorials from the same category :
Building a Subscribe/Unsubscribe App in PHP with Dreamweaver CS3
Intro To Object: Option Variables
Random Password Generation
PHP Thumbnail Generation Script
RSS Feed from a MySQL Database
Understanding and Validating Integers in PHP
Simple swear filter tutorial
Dynamic PHP Google Sitemap
Hide .php extension with url rewriting using .htaccess
Sending SMS with PHP













