Jump to content

Show new added records


Cyto

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/267899-show-new-added-records/
Share on other sites

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.