By Szklana on
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?
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>";
Comments
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:
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?
If anyone's still interested
If anyone's still interested (since this was a topic of quite some time ago), you need to load the user that you're currently viewing. The above snippet works fine, but just need one adjustment:
Now that you're loading the user that you're viewing (user_load(arg(1))), as long as you set block visibility to show on user and/or user/* , it'll load the profile you're viewing and output the appropriate status.