Welcome to WebmasterWorld Guest from 54.167.252.62

Forum Moderators: bill & werty

Message Too Old, No Replies

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.

<?php
header("Content-Type: application/rss+xml; charset=utf-8");
?>
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>My feed</title>
<link>http://www.somesite.com</link>
<description>Random ravings </description>
<?php
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>";
}
?>
</channel>
</rss>


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)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Have you tried validating the feed?
[validator.w3.org...]

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)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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.

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

redhat



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)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month