homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / RSS, ATOM, and Related Technologies
Forum Library, Charter, Moderators: bill & werty

RSS, ATOM, and Related Technologies Forum

automatic rss feed for my php website

 10:57 pm on Jul 26, 2010 (gmt 0)

Hello, I have lurked these forms for many weeks now, and this is my first post here.

I am currently building a PHP website and I am trying to create an RSS feed that will automatically update the content of a blog database into the feed. So far, nothing I have done has worked. The closest I've been able to get is seeing the RSS feed page with the channel and description, but the content does not appear.

The file is called rss.php, and this is the code I am using.

header("Content-Type: application/rss+xml; charset=utf-8");
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<title>My feed</title>
<description>Random ravings </description>
include ('database.php');
$sql = "SELECT * FROM blog_posts ORDER BY timestamp DESC LIMIT 5";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$date = date("M d", $row ['timestamp']);
$title = $row['title'];
$id = $row['id'];
$entry = $row['entry'];
echo "<title>" . $title . "</title>";
echo "<link>blog.php?id=" . $id . "</link>";
echo "<description>" . $entry . "</description>";

But here is a screenshot of how the code looks when I open the browser. [i28.tinypic.com ]

database.php would be my mySQL login info. I am running this code through my WAMP server. I am absolutely sure that the content is being pulled from the database, because if I remove the XML markups, the content is there.

I am assuming that I need to edit my server settings to allow XML to read PHP scripts, but I don't know how to do that. Any help would be appreciated. Thanks!



 1:57 am on Jul 27, 2010 (gmt 0)

Addendum: I just realized that when I edited this script to post, I had accidentally removed the "item" tags in the "while" script. I assure that the item tags are in fact in place, so they are not the cause of the problem.


 12:54 pm on Jul 27, 2010 (gmt 0)

Welcome to WebmasterWorld kaboomboom

>> because if I remove the XML markups, the content is there

so the content disappears just when you add the 3 echo lines?

and the screen shot is nice, but when you view the actual source of the page do you see anything? often that gives clues as to where the issue is.


 1:58 pm on Jul 27, 2010 (gmt 0)

Have you tried validating the feed?

I see some potential problems. If any of your $title, $id, or $entry (or any other variables you decide to output) contains any HTML or XML elements, that may cause a problem.


 3:36 pm on Jul 27, 2010 (gmt 0)

Nevermind, saw the earlier post about "<item>" tags.


 2:38 am on Jul 28, 2010 (gmt 0)

Thanks for the input.

I found a different strategy, which was to simply use php to write inside an xml file when I post through my blog instead of running a php file as an xml file. It seems to have solved my problem as my feed looks perfect now.



 12:27 pm on Nov 3, 2010 (gmt 0)

The following message was cut out to new thread by bill. New thread at: rss_atom/4226901.htm [webmasterworld.com]
10:38 am on Nov 5, 2010 (jst +9)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / RSS, ATOM, and Related Technologies
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved