PDA

View Full Version : Questions about RSS feeds with PHP/MySQL



rvturnage
November 8th, 2006, 12:40 PM
I've found tutorials on how to create XML files for RSS using PHP and MySQL, but they don't seem to tell exactly how to implement them within an existing site...I have a site with a news page that pulls the links, headlines and descriptions from an existing MYSQL database. I'm interested in implementing an RSS feed for our news, but am unsure what steps to take.

Do I need to redo my PHP so that when the news page is loaded it takes the info from the MySQL query, writes it to an XML file, and then parse that XML file to populate the news page?

Or is there a better way to do this?

Sorry for the basic, and probably dumb, question...but I just can't see what to do. I'm sure I'm making it harder than it needs to be.

simplistik
November 8th, 2006, 02:21 PM
lol i was just about to ask this same question... anyone wants to chime in we'd both be grateful :D, at least I know I would. The tutorial that I was reading was...
http://www.webreference.com/authoring/languages/xml/rss/custom_feeds/

Maybe I missed something cause I get the error


XML Parsing Error: junk after document element
Location: http://link.com/rss/news/
Line Number 2, Column 1:<b>Parse error</b>: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}'

bwh2
November 8th, 2006, 03:36 PM
Do I need to redo my PHP so that when the news page is loaded it takes the info from the MySQL query, writes it to an XML file, and then parse that XML file to populate the news page?no. you're thinking about it backwards. think of it like this:
http://img502.imageshack.us/img502/2945/newsupdatect7.th.gif (http://img502.imageshack.us/my.php?image=newsupdatect7.gif)

rvturnage
November 8th, 2006, 05:02 PM
Thanks, bwh2...that helps a lot. Basically, I create an rss file, rss.php, that will pull the info from the database, and format it as XML . Then I link to that rss.php file in the head content of my existing news page, and any other page I want the link on, like so:

<link rel="alternate" type="application/rss+xml" title="RSS News Feed" href="http://www.myurl.com/rss.php" />

for what it's worth, simplistik, I used this tutorial, and have it working with no trouble now:
http://www.phpfreaks.com/tutorials/139/0.php


Thanks for the help!

bwh2
November 8th, 2006, 05:55 PM
yeah, that method works well also. perhaps better. i'd have to think about it. i suppose it depends on how often your RSS file is being pulled by users because that will change how much processing power is required. it should always be fairly speedy though.

bwh2
November 14th, 2006, 03:06 AM
this might also provide some insight: http://fishbowl.pastiche.org/2002/10/21/http_conditional_get_for_rss_hackers