Help with online/offline user status.
Szklana - April 20, 2008 - 14:00
I am using drupal 6.2. I got the code for drupal 5.x ,the error is like that:
Status
Fatal error: Call to undefined function db_num_rows() in C:\AppServ\www\modules\user\user-profile.tpl.php on line 20
Anyone can make that work for drupal 6.x?
<?php
print "<div class=\"fields\">";
$time_period = variable_get('user_block_seconds_online', 600);
$users = db_query("SELECT DISTINCT(uid), access FROM {users} WHERE access >= %d AND uid = %s", time() - $time_period, $user->uid);
$total_users = db_num_rows($users);
if ($total_users == 1)
{
$output = t($user->name.' is currently online');
}
else
{
$output = t($user->name.' is currently offline');
}
print $output;
print "</div>";
?>
Check out...
http://drupal.org/node/236969
thanks a lot.. :)
thanks a lot.. :)
By the way, you shouldn't
By the way, you shouldn't replace the num_rows with the COUNT() solution mentioned in the other thready. The better solution is:
<?php
print "<div class=\"fields\">";
$time_period = variable_get('user_block_seconds_online', 600);
$users = db_query("SELECT DISTINCT(uid), access FROM {users} WHERE access >= %d AND uid = %s", time() - $time_period, $user->uid);
if (db_fetch_array($users))
{
$output = t($user->name.' is currently online');
}
else
{
$output = t($user->name.' is currently offline');
}
print $output;
print "</div>";
?>
Here you only do 1 query which either has a result or not. A COUNT() operation can be much more expensive.
Ok it works.. but.. it only
Ok it works.. but.. it only displays that I am online.. when I try to check other user profile it still displays like: Szklana is online.. and I would like to display if the user that I am checking is online ;S
Any idea?