HomePHP Page 5 - Rockin’ RSS with PHP on your HTML
Adding content - PHP
An RSS feed lets webmasters tease visitors into returning to their websites again and again to check out new content. Danny Wall explains how to set up this simple, automated, spamless way of getting Web surfers to come back for more.
At this point, you now need to begin adding the “item” level information; which is simply the content that has been added to your site. Before we get started on this, there are some things you need to know.
Generally, an RSS feed contains not only the most recently added content to your site, but quite a bit of “back” content as well. This is to allow any new users to not only see the most recent additions, but also see what has been done before they picked up your feed. This way, they'll easily be able to look at that as well.
It’s a good thing for the new user, and for you, as often a person that picks up a new feed will spend some time checking out a lot of the “past” content and catching up on what you’ve got going.
That means we need to do two things.
First, you need to database your new content. In otherwords, you should be adding new content to your database, and your website should be pulling that new content out of the database. This will allow you to utilize PHP with maximum benefit and speed to build the RSS file.
$db = mysql_connect("localhost","your_db_uid","your_db_pw"); mysql_select_db("db_name",$db); $content_sql = "select * from content where page='index' order by id desc";
Obviously in the above line, you are seeing how I do it. Your query may be different depending on how you are databasing your content.
$content_result = mysql_query($content_sql);
So far, we’re still in the “basic” neck of the woods. In fact, all we need to do now is pull the content out of your site and put it into the RSS file.
while ($content_rec = mysql_fetch_row($content_result)) { fwrite ($pd, "<item>");