troubleshooting Question

Insert RSS into mysql Database

Avatar of rhiannon1
rhiannon1 asked on
Web Languages and StandardsLinux Distributions
2 Comments1 Solution4406 ViewsLast Modified:
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 //
 
?>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros