Link to home
Start Free TrialLog in
Avatar of rhiannon1
rhiannon1

asked on

Insert RSS into mysql Database

I am trying to save some XML/RSS data from my page into my MYSQL datasbse using PDO.

I have finaly parsed and external RSS feed and i am displaying the articles on my site. /all is working fine so far in that respect. Now what i want to do, but unable to figure out how to do it is this.

Each article dispayed on my page has a checkbox next to it, and a submit button on the bottom of the page, I want to beable to have a user, check articles and then save articles into my mysql database,  which they will beable to retrieve at a later date.

I want to save to a table called 'articles'  the title, link, and cateogory(which will be either smoking or neuroscience) also need to retrieve the full article and save that to the field 'body'.  

So at the moment the title and link are being shown on my page, ( <a href='$friendly'>$RSSitem->title</a>), but how do i save to the database, and also pull out and save the whole document body. i.e http://www.medicalnewstoday.com/printerfriendlynews.php?newsid=134827.

Really stuck on this, I have got so far, now just hit the brick wall : (   any ideas ?

Thank You.


<?PHP
 
require_once("dbCon/dbcon.php");
 
try {
/*  query the database */
$db = getCon();
 
/* Parse XML from  http://www.medicalnewstoday.com */
$RSS_DOC = simpleXML_load_file('http://www.medicalnewstoday.com/rss/smoking.xml');
 
/* Get title, link, managing editor, and copyright from the document  */
$rss_title = $RSS_DOC->channel->title;
$rss_link = $RSS_DOC->channel->link;
$rss_editor = $RSS_DOC->channel->managingEditor;
$rss_copyright = $RSS_DOC->channel->copyright;
 
//Loop through each item in the RSS document
 
foreach($RSS_DOC->channel->item as $RSSitem) {
// modify string from articles  //
$friendly = str_replace(array('.php', 'articles/'), array('', 'printerfriendlynews.php?newsid='), $RSSitem->link);
 
//  form //
$page->addToContent("<form action='rssNeuroScience.php' method='post' />");
	
	//The variable $RSSitem will hold a different item for each loop
		$page->addToContent("<b><a href='$friendly'>$RSSitem->title</a></b><br /><br />");
		$page->addToContent("<b>$RSSitem->pubDate</b><br /><br />");
		$page->addToContent("$RSSitem->description<br /><br />");
		$page->addToContent("<input name='cBox' type='checkbox' value='cBox'/><br />");
		//$page->addaddToContent("-------------------------------------------------------------<br />");
}
$page->addToContent("<input type='submit' value='submit'/></form>");
// End of form //
 
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the points.  Good luck with your project, ~Ray