Jump to content

Archived

This topic is now archived and is closed to further replies.

netfrugal

How do I create an RSS feed with PHP?

Recommended Posts

I need help here.  I see so many xml rss feeds out there and wonder how they dynamically populate their feeds.

Below is the code I am using from a tutorial I found online. But I still get validation errors that I simply do not understand. I've tested the feed on 3 different readers: Mozilla thunderbird, RssReader 1.0, and FeedReader 2.90.

The tutorial showed me to create the feed with a .php extension.  Are not RSS feeds in XML? 

You can test the feed at marcsteele.com/z.php in a rss reader.
FeedValidator.org gives me the following errors:
http://www.feedvalidator.org/check?...teele.com/z.php

The weird thing is that I can get it to work on my localhost db, but not when I upload it to my server and call data from the production server's db.

I am using IIS for the production server, and apache for my localhost. I can't image why that would make a difference.

The only other issue I can image that is affecting the output is maybe apostrophes or special characters. Any help would be appreciated.

My code:

<?
header("Content-Type: text/xml;charset=utf-8");
$connection = @mysql_connect("localhost", "root", "password");
$db = @mysql_select_db('pl', $connection);
$sql = "SELECT * from products_description";
$result = @mysql_query($sql, $connection);
ECHO <<<END
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Testing Oscommerce RSS Feeds</title>
<link>http://localhost/</link>
<description>Testing out Dynamic RSS feed from mysql.</description>
END;
while($row = mysql_fetch_array($result)) {
$name = $row['products_name'];
// display an item
ECHO <<<END
<item>
<title>$name</title>
<link></link>
<description></description>
</item>
END;
}
ECHO <<<END
</channel>
</rss>
END;
?>

Share this post


Link to post
Share on other sites
Have you tried correcting the errors generated?

You have formatting in your XML, I don't think that's correct, I think you have to have a seperate stylesheet for formatting.

Try making changes as suggested by feed validator.

1. Remove the [code=php:0]<br>[/code] tag.
2. Get rid of the [code=php:0]<b>[/code] tags.
3. Make sure the SQL actually works first by using something like phpMyAdmin.

Regards
Huggie

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.