user1024383
user1024383

Reputation: 15

PHP & MySQL Counting records with a timestamp of under 5 minutes ago

I have a 'users online' function on my C# program, every 3 minutes it will notify the server that the user is still here, when that happens it will preform a query to my database updating it with the users username and a PHP timestamp (time();) if the username is already in the database then it will just update the timestamp.

What I am trying todo is count the users online, I want todo this by counting the number of records which were last seen at maximum 5 minutes ago and then echo out that number. I am not sure how I could go about doing this so any help is greatly appreciated.

Upvotes: 1

Views: 1429

Answers (1)

Marc B
Marc B

Reputation: 360692

The basic query would be:

SELECT count(*) AS cnt
FROM yourtable
WHERE timestampfield >= DATE_SUB(now() INTERVAL 5 MINUTE)

Upvotes: 3

Related Questions