Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.