| | |
RSS file generated from DB table, Automatically? Any tips?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 78
Reputation:
Solved Threads: 1
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.
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.
•
•
Join Date: Sep 2008
Posts: 2
Reputation:
Solved Threads: 2
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.
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.
•
•
Join Date: Mar 2008
Posts: 78
Reputation:
Solved Threads: 1
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 '<rdf
eq>' 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.
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 '<rdf
eq>' 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
•
•
Join Date: Mar 2008
Posts: 78
Reputation:
Solved Threads: 1
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.
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.
php Syntax (Toggle Plain Text)
<?php $host = "localhost"; $user = "username"; $pass = "password"; $database = "name of DB"; $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); mysql_select_db($database, $linkID) or die("Could not find database."); $query = "SELECT * FROM updates ORDER BY id DESC"; $resultID = mysql_query($query, $linkID) or die("Data not found."); $xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $xml_output .= "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n"; $xml_output .= "<channel>\n"; $xml_output .= "<title>Title of whole feed</title>\n"; $xml_output .= "<link>link for whole feed</link>\n"; $xml_output .= "<description>Description of whole feed</description>\n"; $xml_output .= "<language>en</language>\n"; for($x = 0; $x < mysql_num_rows($resultID); $x++){ $row = mysql_fetch_assoc($resultID); $xml_output .= "\t<item>\n"; $xml_output .= "\t\t<title>" . $row['title'] . "</title>\n"; $xml_output .= "\t\t<link>" . $row['link_dest'] . "</link>\n"; $xml_output .= "\t\t<description>" . $row['description'] . "</description>\n"; $xml_output .= "\t\t<guid isPermaLink=\"true\">http://www.yoursite.com#".$row['id']."</guid>\n"; $xml_output .= "\t</item>\n"; } $xml_output .= "</channel>\n"; $xml_output .= "</rss>"; $filename_path = '../feeds/filename_'.$_COOKIE['lang'].'.xml'; $file_write = file_put_contents($filename_path, $xml_output); ?>
Last edited by rickya100; Sep 8th, 2008 at 10:58 am. Reason: text change
![]() |
Other Threads in the PHP Forum
- Previous Thread: php book
- Next Thread: creating RSS for forum
| Thread Tools | Search this Thread |
advanced apache api array beginner binary broken cakephp check checkbox class cms code cookies cron curl database date datepart display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google head href htaccess html if...loop image include includingmysecondfileinthechain insert ip javascript job joomla jquery key library limit link login mail menu mlm multiple mysql oop password paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search server sessions smarty sms sorting source space sql startup stored syntax system table traffic tutorial unicode update upload url validator variable video web youtube zend





