Reputation: 1233
Wondering if there is a way to do this without using two hits to the sql database.
If a person views content the timestamp is recorded.
If the person views the same content again 2 hours later the timestamp is not updated.
If the person views the same content 10 hours after first viewing the content, update the timestamp db table field.
Any method of doing this via SQL and not doing a "select" than php comparison than an "update" ??
Upvotes: 1
Views: 86
Reputation: 78886
update mytable
set lastvisited=now()
where person='john' and lastvisited<(now()-interval 10 hour);
Upvotes: 4
Reputation: 4293
Try
UPDATE tabel_name SET column_name=NOW() WHERE TIMESTAMPDIFF(HOUR, NOW(), column_name) >= 10
Upvotes: 1