Jump to content

Need Help With - Online/Idle/Offline


gaza165

Recommended Posts

I am trying to write a function that allows me to display whether a user is online, offline or idle..

 

this is what i have so far....

 

<?php

include("dbconnect.php");

$sql = mysql_query("SELECT * FROM users WHERE TIMESTAMPDIFF(MINUTE,last_activity, CURRENT_TIMESTAMP()) < 5");
$query = mysql_query("SELECT * FROM users WHERE TIMESTAMPDIFF(MINUTE,last_activity, CURRENT_TIMESTAMP()) > 5");

$numrows = mysql_num_rows($sql);


echo "<h4>".$numrows." users online</h4>";


echo "<ul class='online'>";
while($row = mysql_fetch_array($sql)) {


echo "<li>";
echo $row['username'];
echo "</li>";

}

echo "</ul>";



?>

 

Can you help me a little further please!!!

 

BTW I have this page set to run every 4 seconds to keep it constantly updating users statuses!

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/153902-need-help-with-onlineidleoffline/
Share on other sites

Help you further how?  You don't say if there is a problem, if there is a error, if it works, if it doesn't work...

 

Also, why would you need this to run every 4 seconds?  Just have it run whenever that page you want the status displayed on to accessed.

 

And finally, what is "Idle"?  You won't need that.

 

 

Can you help me a little further please!!!

 

BTW I have this page set to run every 4 seconds to keep it constantly updating users statuses!

 

Thanks

Well I am using jquery, so no refreshes or posts are being made to the page, it is one static page.

 

$sql = mysql_query("SELECT * FROM users WHERE TIMESTAMPDIFF(MINUTE,last_activity, CURRENT_TIMESTAMP()) < 5");

//This checks to see if a user is still online...


$query = mysql_query("SELECT * FROM users WHERE TIMESTAMPDIFF(MINUTE,last_activity, CURRENT_TIMESTAMP()) > 5");

//Then after 5 mins of inactivity I would like it to change the status to idle.

 

Then, finally get it to remove the user from the list to show they are offline!! sort of like a timeout

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.