I have a TIMESTAMP field on MySQL, and I refresh this field everytime a user do something into the site, but I have to show if this user is really online at that momment, and for that, I need to make a query that takes all the results from a table where this TIMESTAMP field is equal or less than 30 seconds. How can I do this kind of query?
Example, it's 2014-07-07 07:55:30 and I want to return all the users between 2014-07-07 07:55:00 and 2014-07-07 07:55:30.
I tried:
[...]WHERE `online_users`.`time` >= timestamp(DATE_SUB(NOW(), INTERVAL 30 SECOND ))
And it didn't work. It shows the result, but it shows even if the interval is longer than 30 seconds, I don't understand why.