How to update date into mysql from external RSS subion?

Discussion in 'PHP' started by youlichika, Oct 26, 2010.

  1. #1
    I want to subscribe a external RSS feed, it with 10 items. and I want to store it into mysql database. When I refresh the page, the database can uptade, the new 10 rss items will replace the older 10.
    require_once ('conn.php');
    mysql_select_db("my_db", $db);
    mysql_query("REPLACE INTO rss (link, title, date, content) VALUES ('".$link."', '".$title."', '".$date."', '".$content."')");
    HTML:
    I tried Insert and REPLACE, but they all insert new one behind the old.
    How to do a update? Thanks.
     
    youlichika, Oct 26, 2010 IP
  2. themullet

    themullet Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #2
    
    $qid = mysql_query("SELECT title FROM rss WHERE title='$title' AND date='$date' AND content='$content' AND link='$link' LIMIT 1");
    if (mysql_num_rows($qid)==0) {
     mysql_query("INSERT INTO rss (link, title, date, content) VALUES ('".$link."', '".$title."', '".$date."', '".$content."')");
    }
    
    PHP:
    only now inserts if not found
     
    themullet, Oct 26, 2010 IP
  3. youlichika

    youlichika Greenhorn

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    Thanks themullet, but
    mysql_num_rows(): supplied argument is not a valid MySQL result resource wrong in line: if (mysql_num_rows($qid)==0) {
    I replace $qid into $query, but it also alart wrong.
    I checked the mysql database, it also insert new rss items when I refresh the page.
     
    youlichika, Oct 26, 2010 IP