IF within 10 minutes from certain time

131 Views Asked by At

I'm trying to create a Users Online page for my site with just php. I have a table column called lastactive which is updated as a DATE/TIME (example: 2014-12-13 21:04:15) each time they visit a page.

Now I want my Users Online page to show all of the users who have been active within the last 10 minutes of the current time. So if it was 10pm, I'd want a users active from 9:50pm-10pm to show.

I found a previous StackOverflow question (can't find it now) that gave me some tips so I tried that and I ended up with this:

$timequery = mysqli_query($con,"SELECT times.lastactive FROM times WHERE lastactive >= NOW() - INTERVAL 10 MINUTE ORDER BY lastactive");

and

$whoisloggedin = mysqli_query($con,"SELECT username FROM users LEFT JOIN times ON times.id=users.id WHERE lastloggedin >= NOW() - INTERVAL 10 MINUTE ORDER BY lastloggedin");

But this just shows every user. Here's what I use to show the user

echo "Shows all active players from the last 10 minutes.";

while ($row = mysqli_fetch_assoc($timequery)) {
   $row2 = mysqli_fetch_array($whoisloggedin);
    $usersArray2 = $row2['username'];
    echo $usersArray2;
}
0

There are 0 best solutions below