|
-
Jul 15th, 2012, 10:51 AM
#1
Thread Starter
Frenzied Member
Display online users
this code shows the top 5 users
how do i get it to show the users that are currently online?
PHP Code:
<?php
$connect = mysql_connect("","","") or die("Couldn't connect!");
mysql_select_db("prkscouk_users") or die("Couldn't find database");
$query = mysql_query("SELECT * FROM users ORDER BY id DESC LIMIT 5");
$numrows = mysql_num_rows($query);
if ($numrows > 0){
while ($row = mysql_fetch_assoc($query))
{
$id = $row['id'];
$username = $row['username'];
$email = $row['email'];
echo "<a href=mailto:$email>$username</a><br>";
}
}
else
{
echo "No users were found.";
}
?>
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Jul 15th, 2012, 08:22 PM
#2
Re: Display online users
First, define "online".
In other words, if I visit a page on your site, when do I stop being online? On this site, for example, it's about ten minutes after the last visit.
To make this work, you need to store the last visit time against each user. When (an authenticated) user visits any page, update this field to the current time. To show all "online" users, select from the users table where the last visit time is less than your predetermined amount of time before the current time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|