user8827281
user8827281

Reputation:

update timestamp just on insert

Last night, I created a column called time in my table, the type is TIMESTAMP and default is CURRENT_TIMESTAMP and attribute is on update CURRENT_TIMESTAMP (all set by default) and it will add timestamp when a new data is inserted, it works fine, and it shows all data (items) on my front page ORDER by this timestamp but this morning I noticed that one of my item's timestamp updated automatically! only hour changed. Now this problem repeated on another item.

Then I figured out that when I open the link to an item (another page that shows all the data belonging to the item), the timestamp will update. In this page I just fetch data from db

print_r($ads);

And the query is simple SELECT FROM TABLE, I'm wondering why this happen?

I know I should post code here, but this is mysql thing and there is no related code. If need, please let me know, then update my post.

Edit: i forget something, when this page open, it increase counter:

$sql = "UPDATE ads SET view = view + 1 WHERE id = $id";

Upvotes: 0

Views: 525

Answers (1)

David J Eddy
David J Eddy

Reputation: 2037

... i just want insert timestamp when new data inserted ...

Change the on update trigger to before insert on. This should limit the time field change action to only when the row is inserted.

Upvotes: 1

Related Questions