RSS file generated from DB table, Automatically? Any tips?

Thread Solved

Join Date: Mar 2008
Posts: 78
Reputation: rickya100 is an unknown quantity at this point 
Solved Threads: 1
rickya100 rickya100 is offline Offline
Junior Poster in Training

RSS file generated from DB table, Automatically? Any tips?

 
0
  #1
Sep 7th, 2008
Hi.

I need to create an RSS file from one table in my database. I'm using PHP5 and MySQL.

I have searched on this and tried to do it myself but i'm not sure what path to take. Should I use SimpleXML to do it?

I am hoping someone might be able to point me in the right general direction. So anyone done this before and can help me out?


Many thanks.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 2
Reputation: RichAppsConsult is an unknown quantity at this point 
Solved Threads: 2
RichAppsConsult RichAppsConsult is offline Offline
Newbie Poster

Re: RSS file generated from DB table, Automatically? Any tips?

 
0
  #2
Sep 8th, 2008
You can get PHP code (class) to gerenrate RSS from

http://forums.digitalpoint.com/showthread.php?t=32265.

Retrieve records from your mysql table, and use above class to generate RSS.

you can dump the output as .xml file .. or an php script can return a rss as well.
Rich Internet Applications
We Code faster....
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 78
Reputation: rickya100 is an unknown quantity at this point 
Solved Threads: 1
rickya100 rickya100 is offline Offline
Junior Poster in Training

Re: RSS file generated from DB table, Automatically? Any tips?

 
0
  #3
Sep 8th, 2008
Hi RichAppsConsult,

Thanks for the page. I had actually come across that one when searching. I didn't use it as there seems to be bits that I don't need in it and I don't enderstand everything it uses such as the '<rdfeq>' namespace use.

I'm looking to just output 4 or 5 text fields from my DB (story_title, story, link, link_title, date) to a simple XML (in RSS format) file.

I don't need images etc and would love to keep it simple at first and just make sure I understand everything.

I see lots of stuff for parsing XML files and I can actually already do that OK but it is not as easy to find something coherent on the issue of outputting XML.
Last edited by rickya100; Sep 8th, 2008 at 5:23 am. Reason: Tryingt o remove smily face
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 831
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 136
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: RSS file generated from DB table, Automatically? Any tips?

 
0
  #4
Sep 8th, 2008
Since the XML output for an RSS is fairly static, I use smarty to generate it, instead of an XML parser.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 78
Reputation: rickya100 is an unknown quantity at this point 
Solved Threads: 1
rickya100 rickya100 is offline Offline
Junior Poster in Training

Re: RSS file generated from DB table, Automatically? Any tips?

 
0
  #5
Sep 8th, 2008
Hi,

Thanks for the two replies.

I just got it working as the second comment came in. I thought would post up the code for others.

Basically it connects to a table and keeps adding text to the $xml_output variable and then writes what is in the variable to an xml file.

In it's current state I am still trying to get it to validate but it worked for me so should get you going.

  1. <?php
  2. $host = "localhost";
  3. $user = "username";
  4. $pass = "password";
  5. $database = "name of DB";
  6.  
  7. $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
  8. mysql_select_db($database, $linkID) or die("Could not find database.");
  9.  
  10. $query = "SELECT * FROM updates ORDER BY id DESC";
  11. $resultID = mysql_query($query, $linkID) or die("Data not found.");
  12.  
  13. $xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  14. $xml_output .= "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n";
  15. $xml_output .= "<channel>\n";
  16. $xml_output .= "<title>Title of whole feed</title>\n";
  17. $xml_output .= "<link>link for whole feed</link>\n";
  18. $xml_output .= "<description>Description of whole feed</description>\n";
  19. $xml_output .= "<language>en</language>\n";
  20.  
  21. for($x = 0; $x < mysql_num_rows($resultID); $x++){
  22. $row = mysql_fetch_assoc($resultID);
  23. $xml_output .= "\t<item>\n";
  24. $xml_output .= "\t\t<title>" . $row['title'] . "</title>\n";
  25. $xml_output .= "\t\t<link>" . $row['link_dest'] . "</link>\n";
  26. $xml_output .= "\t\t<description>" . $row['description'] . "</description>\n";
  27. $xml_output .= "\t\t<guid isPermaLink=\"true\">http://www.yoursite.com#".$row['id']."</guid>\n";
  28. $xml_output .= "\t</item>\n";
  29. }
  30.  
  31. $xml_output .= "</channel>\n";
  32. $xml_output .= "</rss>";
  33.  
  34. $filename_path = '../feeds/filename_'.$_COOKIE['lang'].'.xml';
  35.  
  36. $file_write = file_put_contents($filename_path, $xml_output);
  37.  
  38.  
  39.  
  40. ?>
Last edited by rickya100; Sep 8th, 2008 at 10:58 am. Reason: text change
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC