Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Question help to update db record if record data has changed from last time?

    Hi All,

    I Have an script which inserts records into my db and this script is run every hour to keep everything up to date, i then have an rss feed which posts the latest items to twitter/facebook etc which works fine.

    the problem im having is that if a record is being added to my db table which is already in there but it has a field which has changed from the last time it was inserted how do i overwrite the data in that field

    for example here is my code
    PHP Code:
                            $insert_codes "INSERT INTO 
                            codes (codeID, codeLink, storeID, details, datestamp, expireDate) 
                            VALUES ('$sCode', '$sUrl', '$iId2', '$sDescription', '$date', '$sEndDate') ON DUPLICATE KEY UPDATE expiredate='$sEndDate' details='$sDescription'"

    which is updating expiredate and details if a duplicate ID is found now i want to update the timestamp also only if the data being updated is different from that which was already in there

    hope this makes sence?
    any help is appreciated

    Luke

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    Create an additional column in your table call hash. Take the raw RSS data for each record and do a sha1 or md5 hash (sha1 is preferable due to the lower number of potential collisions) and store that in the record with the rest of the data. Every time you pull data from the RSS, you can do the same hash and check to see if the hash values are different. If they are, you can do an update.


  •  

    Posting Permissions

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