I’m reading and store a RSS feed in my database.I’m using this code
<?php
include_once 'db.php';
$homepage = file_get_contents('http://rss.cnn.com/rss/edition_us.rss');
$movies = new SimpleXMLElement($homepage);
foreach($movies->channel->item as $opt){
$title= $opt->title;
$tittle=mysql_real_escape_string($title);
$link=$opt->link;
$links=mysql_real_escape_string($link);
$des=$opt->description;
$dess=mysql_real_escape_string($des);
$sql="INSERT INTO store_feed (title, link, description)
VALUES ('$tittle','$links','$dess')";
$result=mysql_query($sql) or die('Error, insert query failed');
}
?>
and table structure is
Table structure for table store_feed
CREATE TABLE IF NOT EXISTS `store_feed` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(200) NOT NULL,
`link` varchar(200) NOT NULL,
`description` varchar(500) NOT NULL,
`feedburner` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
now my requirement is when insert a new record if link is same then update only title and description of this field without insert record again.
in other word I want to stop duplicate data if link is same.
Usually, I do something like this:
WARNING: UNTESTED CODE!