Q:

Echo how many users is online in last 5 minutes

So, I am wondering how can I get number of last online users from mysql database? 
In MySQL 'lastonline' is 2015-07-12 12:00:13am
So I need to get number of users where is lastonline under 2015-07-12 12:05:00am
I tried:
$currenttime = date("Y-m-d h:i:sa");
    $resulttt = mysql_query("select lastonline from users where lastonline <= '$currenttime'");
$users = mysql_num_rows($resulttt);
echo "$users";

I got 0, but when I change from '<=' to '=>' I got 40 (number of all my users)
How is possible to calculate number of online users under 5 minutes? 
Thanks for help, really appreciated. 
Also tried: SELECT lastonline FROM users WHERE lastonline > now() - INTERVAL 5 MINUTE
Just got number of all users

A:

The best way to do it would be using MySQL only.  This query allows you to select all rows between now and 5 minutes ago:
SELECT lastonline FROM users WHERE lastonline > now() - INTERVAL 5 MINUTE
or
SELECT lastonline FROM users WHERE lastonline > DATE_SUB(now(), INTERVAL 5 MINUTE)
However, it's possible to use PHP instead.  The code would be as follows:
$5_minutes_ago = date("Y-m-d H:i:s",mktime(date("H"),(date("i")-5),date("s"),date("m"),date("d"),date("Y")));
$resulttt = mysql_query("SELECT lastonline FROM users WHERE lastonline > ".  $5_minutes_ago) or die(mysql_error());
$users = mysql_num_rows($resulttt);
echo $users;

On a last note: mysql_* is officialy deprecated.  I strongly suggest updating your code to MySQLi or PDO.  The added benefit is that you'll be able to use Prepared Statements, which will protect you against SQL injection.