Cyto Posted September 1, 2012 Share Posted September 1, 2012 Hi, Lets say the script is searching something and finds some records and at the same time it updates his records for new ones. (I have succesfully done this, no issues here) I would like to show the new added records with timestamp. This is what I have so far: $sql = "SELECT * FROM records WHERE timestamp > (NOW() - INTERVAL 30 SECOND)"; This code shows the old records again. I want it to show only records that are new added. If someone can help me. thanks. -Cyto Quote Link to comment https://forums.phpfreaks.com/topic/267899-show-new-added-records/ Share on other sites More sharing options...
Barand Posted September 1, 2012 Share Posted September 1, 2012 Fields of type TIMESTAMP are updated automatically when a row is INSERTED or UPDATED. You have a couple of options. When you update, set the timestamp field to itself to prevent update to current time or Make it a DATETIME field and set the value to NOW() on insert Quote Link to comment https://forums.phpfreaks.com/topic/267899-show-new-added-records/#findComment-1374563 Share on other sites More sharing options...
Cyto Posted September 1, 2012 Author Share Posted September 1, 2012 I explained it wrong. The old records don't get updated, but new ones come. I'm trying to get only the new added records. Timestamp looks like this: 2012-09-01 21:29:06 Quote Link to comment https://forums.phpfreaks.com/topic/267899-show-new-added-records/#findComment-1374566 Share on other sites More sharing options...
DavidAM Posted September 1, 2012 Share Posted September 1, 2012 There is a big difference between "updates his records" and "new added records". Are you saying you used an INSERT statement and want to return the rows that were inserted? If the records were INSERTed, and the table has an AUTO_INCREMENT column, you need to capture the value of that column after the first INSERT and return all rows >= (greater than or equal to) that column. Note that it is possible other users inserted data at the same time, so you will probably want to limit the rows returned to rows created by the user. To do this, you need to have a column in the table that you put the user's ID into when the record is created. Quote Link to comment https://forums.phpfreaks.com/topic/267899-show-new-added-records/#findComment-1374569 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.