homepage Welcome to WebmasterWorld Guest from 54.211.230.186
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
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
kaboomboom



 
Msg#: 4176957 posted 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!

 

kaboomboom



 
Msg#: 4176957 posted 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.

jatar_k

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



 
Msg#: 4176957 posted 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.

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4176957 posted 1:58 pm on Jul 27, 2010 (gmt 0)

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.

whoisgregg

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



 
Msg#: 4176957 posted 3:36 pm on Jul 27, 2010 (gmt 0)

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

kaboomboom



 
Msg#: 4176957 posted 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!

System
redhat


 
Msg#: 4176957 posted 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