Results 1 to 2 of 2

Thread: How to judge RSS source, if there has new then UPDATE into database?

  1. #1
    Join Date
    Aug 2010
    Posts
    47

    How to judge RSS source, if there has new then UPDATE into database?

    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.

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

  2. #2
    Join Date
    Feb 2007
    Location
    Ireland
    Posts
    1,007
    There are a few ways you can do it. The publication date tag is optional but yahoo news seems to implement it. You can use that as you're timestamp. Read the RSS document, parse and insert into your database. When you go to read it again, get the timestamp of the last record, and don't store items before that timestamp. I didn't check to see if the feed was ordered, but ensure you insert records into the database in a proper order (by timestamp).

    Also, don't just store the timestamp in the RSS feed. Parse it and store it as a DATETIME type. This will give you more control in your queries, making them easier to write.
    “The best thing about a boolean is even if you are wrong, you are only off by a bit.”

Similar Threads

  1. Rss Image Thumbnail Generation and Database
    By cpbunch in forum General Questions
    Replies: 0
    Last Post: 01 Jan 2010, 04:59 PM
  2. Get & Auto-Update From RSS Feed
    By tylerplack in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 25 Nov 2009, 03:06 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •