I have ordered yahoo news rss, I use simplepie to separate the news items like title, content, url, date... and then insert them into database. I catch the source every 2 hours with cron. How to judge RSS source, if there has new then UPDATE into database?

I mean if the rss source has 10 items, 5 are old, 5 are new, I want just update the 5 items new and ignore the 5 old items. I do not want insert the repeart items.
And I want to get `echo` a list of the 5 new items.

This is my insert code.

mysql_select_db("rss",$db1);
mysql_query("INSERT INTO yahoonews (link, title, date, content, image, imagelink) VALUES ('".$link."', '".$title."', '".$date."', '".$content."', '".$image."', '".$imagelink."')");

Compare the link or title with the date from the rss against your database.

Create hashes for the common fields that change. I'm thinking the title and content/body of each article. Store these two hashes with each item in your database.

When you process the feed again, generate the same hashes and look for any records where both hashes match. If you find a result disregard the item from the rss feed as it is identical to one in the database already.

When you find a mismatched title or body hash, update whichever of the fields does not match with the changes.

When you find no match on the title or body hash, insert the new item into your database.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.