View Full Version : help to update db record if record data has changed from last time?

07-01-2010, 12:30 AM
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

$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


07-01-2010, 04:22 AM
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.