Hi all,
I have a big problem (i think for you it´s small one ;-) ).

I want to have a "Who´s online block" i know there are alot of snippets and modules out there but I´m looking for a special function.

I try to get it look this way :
(10 last logged in users/or online users)

Username (coloured pink if profile_gender = female and light blue if profile_gender = male)
I would also like to have a small icon in front of the username

if profile_gender = male show website.com/drupal/files/male.jpg 25x25px
if profile_gender = female show website.com/drupal/files/female.jpg 25x25px

I´m very sorry but I have two other stupid questions (but I don´t get it on my own):

How can i print this 10 users into 2 columns (5on the right and 5 on the left) ?
And how can I have a border around this whole thing...

I´m very sorry but I don´t get it to work since days/weeks and now I have to annoy you with this newbie questions.

Thanks in advance,
best regards,
Maik

Comments

erika’s picture

i don know how to do it..post it if u r successful

i can just tel u ,u need to modify the code that is meant for who's online block in the htdocs

msolt’s picture

I had the idea myself but i don´t know how to do it. :D

rosgar’s picture

It will take me months to figure it out :D

coreb’s picture

Skip to the bottom of the post to see the final version.

If you want to see the process we went through to get the final version, continue reading.

coreb’s picture

This seems like something that we could figure out together. Let's start with a good base: the Custom "Who's Online" Block. Which version of Drupal are you using?

Assuming that profile_gender is the way it's stored in the DB, we could get the gender out by modifying the original user's query:

$users = db_query('SELECT uid, name, access FROM {users} WHERE access >= %d AND uid != 0 ORDER BY access DESC', time() - $time_period); 

and add profile_gender into the SELECT statement. It would now look like this:

$users = db_query('SELECT uid, name, access, profile_gender FROM {users} WHERE access >= %d AND uid != 0 ORDER BY access DESC', time() - $time_period); 

As for changing the color of the names, there's a couple of ways to do it.

  1. The "Quick and Dirty" Way is to build all the HTML yourself when you pull out the $users. you'll want to overwrite theme_username's output
  2. The Drupal Way™ would be to override the theme functions.

Since I'm still trying to understand the theme functions, I can't help you with exactly how to override them. I can tell you what's getting called where...

This line: $output .= theme('user_list', $items, t('Online users')); calls theme_user_list in modules/user.module.

There's a function call made to theme_username and theme_item_list which are both in includes/theme.inc.

Hopefully this helps you get closer to solving what you're trying to do.

msolt’s picture

Thank you for the great answer. I´m using Drupal 5.x .
This helps me alot... I´m going to try some things... and will leave you message about my hopefully successfull tries ^^

Best regards,
Maik

P.S: If anybody has some good snippets, please let me know...

msolt’s picture

What I got until now is just that...just the ouput of the online users:

$number = db_result(db_query('SELECT COUNT(uid) AS number FROM {users} WHERE status=1'));

        if (user_access('access content')) {
          // Count users with activity in the past defined period.
          $time_period = variable_get('user_block_seconds_online', 900);

          // Perform database queries to gather online user lists.
          $users = db_query('SELECT uid, name, access FROM {users} WHERE access >= %d AND uid != 0 ORDER BY access DESC', time() - $time_period);
          $total_users = db_num_rows($users);

   
          // Display a list of currently online users.
          $max_users = variable_get('user_block_max_list_count', 10);
          if ($total_users && $max_users) {
            $items = array();

            while ($max_users-- && $account = db_fetch_object($users)) {
              $items[] = $account;
            }
            $output .= theme('user_list', $items, t('Online users'));
          }

        }
        return $output;

I had an idea (sorry for the syntax.... ;-) ) I don´t know if it´s possible to code something like this...may be this can help you?!

if profile_gender == ("male")
nameoutput = blue

else 
colour = pink
msolt’s picture

Pleaseee help me :( I´m getting mad

vm’s picture

getting mad doesnt help anyone, nor does bumping more then one post of the exact same question. see: http://drupal.org/node/148200

You may want to seek out someone in the paid drupal forum for this customization. This customization is not that minimal, IMHO.

coreb’s picture

This was taking longer than I thought to build. What you are trying to do is not a simple task. As I said before I don't know how to do this, I'm learning as I go. I do apologize for not responding in a timely manner.

<rant>I check this forum when I have free time. I had higher priority things that needed to be done, because I am paid to do them. Keep in mind, you are using free software. You get what you pay for. Re-read the point that starts "With Volunteer Support..." on the Tips for posting to drupal forums. If you needed immediate support, you should have tried other methods, like going in IRC channels or paying someone (like VeryMisunderstood already said).

Please understand, I'm not trying to insult or berate you, I'm just putting things in perspective.</rant>

There are a couple of ways to do this, and I was trying to figure out the more efficient way. The problem is getting the data in that profile_gender field. I didn't know that it wasn't stored in the {users} table. So the $users = db_query(... that we had won't work. We need to look at other wasy to do this.

One way would be to load all the info for every user that's online, but that would waste alot of time since we only need one profile field. Instead we need to join that profile field to the user data. So change the $users = db_query(... to look like this:

 //Ignore the opening tag, just put it in the right place in the code.
 $users = db_query('SELECT u.uid, u.name, access, v.value as profile_gender  FROM {users} u, {profile_fields} f, {profile_values} v WHERE access >= %d AND u.uid != 0 AND u.uid=v.uid AND f.fid=v.fid AND f.name=\'profile_gender\' ORDER BY access DESC', time() - $time_period);

Now we actually have access to the profile_gender field. Change the code below $total_users = ... to look like this:

 // Display a list of currently online users. $max_users =
variable_get('user_block_max_list_count', 10); 
if ($total_users && $max_users) {
  $items = array();
  while ($max_users-- && $account = db_fetch_object($users)) {
	 $style = "color: "
	 if (strcasecmp(substr($account->profile_gender,0,1),"M"))
		 $style .= "blue";
	 else if (strcasecmp(substr($account->profile_gender,0,1),"F"))
		 $style .= "pink"; //I don't know if you can do this, specify the HEX code for PINK if it doesn't work
	 else $style .= "green";  // I like green
         if (user_access('access user profiles')) { 
	     $items[] = l($account->name, 'user/'. $object->uid, array('title' => t('View user profile.'), 'style' => $style)); 
	 } 
	 else {
		 $items[] = '<span style="' . $style . '">' . check_plain($account->name) . '</style>'; 
	 } 
	 $output .= theme('item_list', $items, t('Online users')); 
  }

} 
return $output; 

I know there's a better way to do the color change by overriding the theme_username function that I mentioned in the last post, but I lack the time to pursue it.

msolt’s picture

Thank you coreb...great work :-)

<so-sorry>
I didn´t wanted you to become rant. I said I become mad because I didn´t solved this problem on my own. Not because i had to wait for an answer.
I´m very sorry if you felt affected (i hope it´s the right word...my english is not perfect).
I´m very thankfull for every help that i get, I try to help other users myself (most times I´m just not good enough ;-) )
</so-sorry>

I tried the code. I found a mistake in the line:

// Display a list of currently online users. $max_users =

This was easy to solve

// Display a list of currently online users. 
$max_users =

Inside this everything seems to be ok:

//Ignore the opening tag, just put it in the right place in the code.
$users = db_query('SELECT u.uid, u.name, access, v.value as profile_gender  FROM {users} u, {profile_fields} f, {profile_values} v WHERE access >= %d AND u.uid != 0 AND u.uid=v.uid AND f.fid=v.fid AND f.name=\'profile_gender\' ORDER BY access DESC', time() - $time_period);

But inside the big block seems to be the failure, i tried out the following:

$number = db_result(db_query('SELECT COUNT(uid) AS number FROM {users} WHERE status=1'));

        if (user_access('access content')) {
          // Count users with activity in the past defined period.
          $time_period = variable_get('user_block_seconds_online', 900);

          // Perform database queries to gather online user lists.
         $users = db_query('SELECT u.uid, u.name, access, v.value as profile_gender  FROM {users} u, {profile_fields} f, {profile_values} v WHERE access >= %d AND u.uid != 0 AND u.uid=v.uid AND f.fid=v.fid AND f.name=\'profile_gender\' ORDER BY access DESC', time() - $time_period);

          $total_users = db_num_rows($users);

   
          // Display a list of currently online users.
       $max_users =variable_get('user_block_max_list_count', 10); 
if ($total_users && $max_users) {
  $items = array();
  while ($max_users-- && $account = db_fetch_object($users)) {
     $style = "color: "
     if (strcasecmp(substr($account->profile_gender,0,1),"M"))
         $style .= "blue";
     else if (strcasecmp(substr($account->profile_gender,0,1),"F"))
         $style .= "pink"; //I don't know if you can do this, specify the HEX code for PINK if it doesn't work
     else $style .= "green";  // I like green
         if (user_access('access user profiles')) { 
         $items[] = l($account->name, 'user/'. $object->uid, array('title' => t('View user profile.'), 'style' => $style)); 
     } 
     else {
         $items[] = '<span style="' . $style . '">' . check_plain($account->name) . '</style>'; 
     } 
     $output .= theme('item_list', $items, t('Online users')); 
  }

} 
return $output; 

I get the error:
Parse error: syntax error, unexpected T_IF in /www/htdocs/*******/includes/common.inc(1342) : eval()'d code on line 20

so it seems to be in this line:

while ($max_users-- && $account = db_fetch_object($users)) {

Again: I´m very sorry :-(

vm’s picture

I believe $max_users = needs to be set to some number.

$max_users = 25

msolt’s picture

Isn´t this solved in this line?

$max_users =variable_get('user_block_max_list_count', 10); 
vm’s picture

ahhh, yes, you are probably correct.

$max_users =variable_get('user_block_max_list_count', 10);

should probably be:

$max_users = variable_get('user_block_max_list_count', 10);

and

while ($max_users-- && $account = db_fetch_object($users)) {
     $style = "color: "

should probably be:

while ($max_users-- && $account = db_fetch_object($users)) {
     $style = "color: ";
coreb’s picture

yes. $style = "color: "; needs the ; on the end. I can't blame that error on moving the code from my code editor to the text box on the page.

coreb’s picture

I am not mad. I obviously misunderstood you. That is the danger of using only text as a form of communication, it is very easy to interpret things the wrong way.

Don't worry, if I tried to speak your native language, you would not be able to understand me at all.

msolt’s picture

I´m glad that you´re not mad :-)
Big thanks also to : VeryMisunderstood :-) :-)

I have an other error:

Parse error: syntax error, unexpected $end in /www/htdocs/w007ae56/includes/common.inc(1342) : eval()'d code on line 36

solved with

}

in line 36 ;-)

But there is something strange... in my profile I´m "male". But my name is displayed pink?!
And female is displayed blue...ok normally this is a simple problem...i changed it this way:

if (strcasecmp(substr($account->profile_gender,0,1),"F"))
         $style .= "blue";
     else if (strcasecmp(substr($account->profile_gender,0,1),"M"))

But there is something else:

It looks like this :
Online users
Test
Online users
Test
Maik

You can see this here:

  • http://webscutest.de/strange.jpg
  • coreb’s picture

    Confession time: I didn't test this code out, since I don't have a working test site right now.

    The strange colors are because I forgot to add the rest of the condition to that. Change it to look like this:

    if (strcasecmp(substr($account->profile_gender,0,1),"M") == 0)
             $style .= "blue";
    else if (strcasecmp(substr($account->profile_gender,0,1),"F") == 0)
    // ...
    

    The code worked exactly like it was written, but it was not written correct. It was looking at your gender and seeing that it matched "M". With strcasecmp(), that returns a 0. But without that == 0, the statement reads as if (0), which is false.

    Oddly enough strcasecmp(), returns >0 when the left string is greater than the right string. Or in your case: M > F. Since it returned something that wasn't 0, the statement reads as if (1), which is true. It's funny that it accidentally did the opposite of what I was trying to do.

    As for your second error, make sure that you didn't copy/paste the code into the text box twice. I'm blocked by a firewall from seeing the picture, but that's my first guess why you see duplicates.

    msolt’s picture

    Ok,
    I have to say; for not testing the code it´s great ^^

    Ok the colorproblem is solved ;-) . By the way "pink" is working.

    I´ve putted it again into another textbox(block).
    Still the same problem:

    Online users
    Maik
    Online users
    Maik
    Test

    The strange thing is , the user I´m logged in with is always inside the first 'online users'.
    That means, when I´m logging in as 'test' it looks like this:

    Online users
    Test
    Online users
    Test
    Maik

    This is the code I´m using:

    $number = db_result(db_query('SELECT COUNT(uid) AS number FROM {users} WHERE status=1'));
    
            if (user_access('access content')) {
              // Count users with activity in the past defined period.
              $time_period = variable_get('user_block_seconds_online', 900);
    
              // Perform database queries to gather online user lists.
             $users = db_query('SELECT u.uid, u.name, access, v.value as profile_gender  FROM {users} u, {profile_fields} f, {profile_values} v WHERE access >= %d AND u.uid != 0 AND u.uid=v.uid AND f.fid=v.fid AND f.name=\'profile_gender\' ORDER BY access DESC', time() - $time_period);
    
              $total_users = db_num_rows($users);
    
       
              // Display a list of currently online users.
           $max_users = variable_get('user_block_max_list_count', 10); 
    if ($total_users && $max_users) {
      $items = array();
      while ($max_users-- && $account = db_fetch_object($users)) {
         $style = "color: ";
        if (strcasecmp(substr($account->profile_gender,0,1),"M") == 0)
             $style .= "blue";
    else if (strcasecmp(substr($account->profile_gender,0,1),"F") == 0)
             $style .= "pink"; //I don't know if you can do this, specify the HEX code for PINK if it doesn't work
         else $style .= "green";  // I like green
             if (user_access('access user profiles')) { 
             $items[] = l($account->name, 'user/'. $object->uid, array('title' => t('View user profile.'), 'style' => $style)); 
         } 
         else {
             $items[] = '<span style="' . $style . '">' . check_plain($account->name) . '</style>'; 
         } 
         $output .= theme('item_list', $items, t('Online users')); 
      }
    }  //added by me to solve the line #36 Problem     i think it was 36
    } 
    return $output; 
    
    coreb’s picture

    $output .= theme('item_list', $items, t('Online users'));
      }

    should be

    } 
    $output .= theme('item_list', $items, t('Online users'));

    The $output line is getting processed for every user that's online (which is 2), when it should only run once.

    msolt’s picture

    Thank you very much...
    this is working perfectly (tested with 2 users).
    With this, I think 80% of my problem is solved.
    Now it should not be very hard to implement a little icon for male/female. I will try to put it into the script.

    I´ve sent you an email, would be great if you would reply to this. So I can invite you to my website, when everything is working :-)

    You´ve saved my evening. And tomorrow evening and so on ^^.

    EDIT:
    I thought it will work when i do this:

    if (strcasecmp(substr($account->profile_gender,0,1),"M") == 0)
             $style .= "blue";
             $image .= (img src="male.jpg");       //for example 15x15px
    else if (strcasecmp(substr($account->profile_gender,0,1),"F") == 0)
             $style .= "pink"; 
             $image .= (img src="female.jpg");    //for example 15x15px
         else $style .= "green";
    

    But I will have to think about this again *rofl* :D

    Best regards,
    Maik

    coreb’s picture

    I had forgotten about the images you wanted. This is one of those cases where CSS would be better for this. So let's revise my code a little. First, you're going to adapt this so that instead of putting in the actual colors, we'll put the users into a class. Here's a quick refresher of the old code

    
     $style = "color: ";//
        if (strcasecmp(substr($account->profile_gender,0,1),"M") == 0)
             $style .= "blue";
    else if (strcasecmp(substr($account->profile_gender,0,1),"F") == 0)
             $style .= "pink"; //I don't know if you can do this, specify the HEX code for PINK if it doesn't work
         else $style .= "green";  // I like green
    
    

    Now, the changed version:

     $class = "";
        if (strcasecmp(substr($account->profile_gender,0,1),"M") == 0)
             $class = "boyuser";
    else if (strcasecmp(substr($account->profile_gender,0,1),"F") == 0)
             $class = "girluser"; 
    

    Now the code on the line
    $items[] = l($account->name, 'user/'. $object->uid, array('title' => t('View user profile.'), 'style' => $style));

    You should replace 'style' with 'class':
    $items[] = l($account->name, 'user/'. $object->uid, array('title' => t('View user profile.'), 'class' => $class));

    The final thing is to go into the theme you're using (which, I believe, is garland) and add some special CSS to the style.css file. I don't know exactly what needs to be added, but here's what can start you off.

    a.boyuser {
    color: blue; /* Recognize this?  That's what the style thingie was doing before */
    padding-left: 18px;
       background: transparent url(male.jpg) no-repeat center left;
    }
    a.girluser {
    color: pink; 
    padding-left: 18px;
       background: transparent url(femailmale.jpg) no-repeat center left;
    }
    

    I don't know if the CSS code is right, I'm adapting it from here. This is starting to get to the area I'm not so familiar with, but here's some reading that may help you:

    http://www.pooliestudios.com/projects/iconize/
    http://developer.mozilla.org/en/docs/CSS:Getting_Started:Content

    Hopefully someone else w/ more knowledge in this area can chime in soon.

    msolt’s picture

    Looks good,
    currently I´m at work. I will try this code afterwards.
    I think I can create this css.

    Sorry wasn´t online yesterday any more...I was fallin´asleep in front of my PC ^^

    I will post my tries ;-)

    msolt’s picture

    Ok I´ve tested it.
    It´s working, but it´s working like the standard "who´s online" module.
    So, no different colors at all ;-)

    Another thing I´m wondering about is this; it looks like this:
    °name1
    °name2
    °name3

    why is that ° in front of the names?
    Is it because it´s a list?

    marcoBauli’s picture

    subscribing

    msolt’s picture

    Hi,
    it´s me again.
    Ok I tested this but it´s not really working.
    I made a mistake but I don´t know where it is?
    This is the script:

    $number = db_result(db_query('SELECT COUNT(uid) AS number FROM {users} WHERE status=1'));
    
            if (user_access('access content')) {
              // Count users with activity in the past defined period.
              $time_period = variable_get('user_block_seconds_online', 900);
    
              // Perform database queries to gather online user lists.
             $users = db_query('SELECT u.uid, u.name, access, v.value as profile_gender  FROM {users} u, {profile_fields} f, {profile_values} v WHERE access >= %d AND u.uid != 0 AND u.uid=v.uid AND f.fid=v.fid AND f.name=\'profile_gender\' ORDER BY access DESC', time() - $time_period);
    
              $total_users = db_num_rows($users);
    
       
              // Display a list of currently online users.
           $max_users = variable_get('user_block_max_list_count', 10); 
    if ($total_users && $max_users) {
      $items = array();
      while ($max_users-- && $account = db_fetch_object($users)) {
         
    $class = "";
        if (strcasecmp(substr($account->profile_gender,0,1),"M") == 0)
             $class = "aboyuser";
    else if (strcasecmp(substr($account->profile_gender,0,1),"F") == 0)
             $class = "agirluser"; 
    
             if (user_access('access user profiles')) { 
            $items[] = l($account->name, 'user/'. $object->uid, array('title' => t('View user profile.'), 'class' => $class)); 
         } 
         else {
             $items[] = '<span style="' . $style . '">' . check_plain($account->name) . '</style>'; 
         } 
    }
         $output .= theme('item_list', $items, t('Online users')); 
      
    }
    } 
    return $output; 
    

    And this is what I added to the style.css :

    aboyuser {
    color: #6666ff; 
    padding-left: 18px;
       background: transparent url(male_p.gif) no-repeat center left;
    }
    
    agirluser {
    color: #ff66ff; 
    padding-left: 18px;
       background: transparent url(female_p.gif) no-repeat center left;
    }
    
    
    vm’s picture

    aboyuser {
    color: #6666ff; 
    padding-left: 18px;
       background: transparent url(male_p.gif) no-repeat center left;
    }
    
    agirluser {
    color: #ff66ff; 
    padding-left: 18px;
       background: transparent url(female_p.gif) no-repeat center left;
    }

    per the css originally given to you, should be:

    a.boyuser {
    color: #6666ff; 
    padding-left: 18px;
       background: transparent url(male_p.gif) no-repeat center left;
    }
    
    a.girluser {
    color: #ff66ff; 
    padding-left: 18px;
       background: transparent url(female_p.gif) no-repeat center left;
    }

    notice the . in a.girluser and a.boyuser

    msolt’s picture

    tried this one:

    a.boyuser {
    color: #6666ff; 
    padding-left: 18px;
       background: transparent url(male_p.gif) no-repeat center left;
    }
    
    a.girluser {
    color: #ff66ff; 
    padding-left: 18px;
       background: transparent url(female_p.gif) no-repeat center left;
    }
    
    

    still the same problem ?!

    That´s strange

    vm’s picture

    if (strcasecmp(substr($account->profile_gender,0,1),"M") == 0)
             $class = "aboyuser";
    else if (strcasecmp(substr($account->profile_gender,0,1),"F") == 0)
             $class = "agirluser";

    You've altered the above code section as well. there should be no a in boyuser or girluser in that code.

    you also did not follow coreb's instruction with this line:

    $items[] = l($account->name, 'user/'. $object->uid, array('title' => t('View user profile.'), 'style' => $style));
    in this comment : http://drupal.org/node/147374#comment-237726

    you have to that line to read:

    $items[] = l($account->name, 'user/'. $object->uid, array('title' => t('View user profile.'), 'class' => $class));
    I highly suggest you, re copy the code given to you by coreb, and replace what you've changed. Then re read the beginning of this thread, specifically coreb's comments.

    msolt’s picture

    Thank you very much.
    But as you can see in my previous post, I´ve followed his instructions:
    ;-)

    if (user_access('access user profiles')) { 
            $items[] = l($account->name, 'user/'. $object->uid, array('title' => t('View user profile.'), 'class' => $class)); 
    

    Thanks it´s working. Thats great.
    I have this:
    ° pic Name
    ° pic Name

    This : ° belongs to block in the css file right? Because it´s a list or am i on a wrong way?

    vm’s picture

    they are bullets.

    using bullets as a search term : brought me these threads: http://drupal.org/search/node/bullets

    This comment : http://drupal.org/node/132205#comment-216372
    on this thread: http://drupal.org/node/132205

    seems to answer your question, using css to remove the bullets.

    erika’s picture

    hi msolt...
    glad that 80% of u'r problem is solved....
    it would be very nice of you if you post the steps once you've achieved what you wanted.That way newbies like me would find very useful...
    please can you put all the steps to achieve your online block
    Thank you

    msolt’s picture

    Hi,
    thank you again Coreb & Miss ;-)

    This is the Version for

    Drupal 5.x

    I don´t know if it will work with other Drupal deployments:
    Ok do the following steps and everything should work fine:

    1.You need the profile field gender.
    Goto: Administer->User management->Profiles
    Add new field : "list selection" insert a category you want, insert a title.
    Form name must be

    profile_gender

    to work properly with the following steps. If you use an other form name you have to change it also in the script.

    Select options should be "male" and "female" without the " " .
    Save the field !

    2. Goto: Administer->Blocks-> Add Block
    Insert a description.
    Insert the following code as body.

    $number = db_result(db_query('SELECT COUNT(uid) AS number FROM {users} WHERE status=1'));
    
            if (user_access('access content')) {
              // Count users with activity in the past defined period.
              $time_period = variable_get('user_block_seconds_online', 900);
    
              // Perform database queries to gather online user lists.
             $users = db_query('SELECT u.uid, u.name, access, v.value as profile_gender  FROM {users} u, {profile_fields} f, {profile_values} v WHERE access >= %d AND u.uid != 0 AND u.uid=v.uid AND f.fid=v.fid AND f.name=\'profile_gender\' ORDER BY access DESC', time() - $time_period);
    
              $total_users = db_num_rows($users);
    
       
              // Display a list of currently online users.
           $max_users = variable_get('user_block_max_list_count', 10); 
    if ($total_users && $max_users) {
      $items = array();
      while ($max_users-- && $account = db_fetch_object($users)) {
         
    $class = "";
        if (strcasecmp(substr($account->profile_gender,0,1),"M") == 0)
             $class = "boyuser";
    else if (strcasecmp(substr($account->profile_gender,0,1),"F") == 0)
             $class = "girluser"; 
    
             if (user_access('access user profiles')) { 
            $items[] = l($account->name, 'user/'. $object->uid, array('title' => t('View user profile.'), 'class' => $class)); 
         } 
         else {
             $items[] = '<span style="' . $style . '">' . check_plain($account->name) . '</style>'; 
         } 
    }
         $output .= theme('item_list', $items, t('Online users')); 
      
    }
    } 
    return $output; 
    

    Set input format to php.
    Save the block !

    3. Open your style.css (you can find it for example here: domain.com/drupal/themes/garland/style.css)
    insert the following code to it:

    a.boyuser {
    color: #6666ff; 
    padding-left: 18px;
       background: transparent url(male_p.gif) no-repeat center left;
    }
    
    a.girluser {
    color: #ff66ff; 
    padding-left: 18px;
       background: transparent url(female_p.gif) no-repeat center left;
    }
    

    upload it to where you got it from ;-)

    4. Create 2 images in this case female_p.gif and male_p.gif.
    The pictures shouldn´t be bigger than 15x15px to look good.
    Upload the pictures into your garland directory.

    5. Goto Administer->Blocks
    Now activate the block.
    For example inside the left sidebar.

    6. Done ! Everything should work now.

    I hope I didn´t forgot something, if it´s not working please let me know.
    Please let me (us) know if everything works fine. If there are any mistakes inside the "tutorial" I´ll correct them later.

    Best regards,
    Maik

    P.S: Please excuse my poor english. I hope you understand the steps :-)

    msolt’s picture

    I´ve found a little bug inside this script.
    Ok. I try to explain this bug.
    When you embed this script into your site, you can see who´s online. Normally when you click on a name inside this list the profile of the specific user gets opened. But not in this script. It always opens YOUR profile.

    I try to figure out, why this happens. If anybody got an good idea. Please post it.

    Thanks

    msolt’s picture

    Ok,
    I think I´ve found the error:

    if (user_access('access user profiles')) { 
            $items[] = l($account->name, 'user/'. $object->uid, array('title' => t('View user profile.'), 'class' => $class)); 
    
    
    

    I need to get the userid behind the 'user/'. ...

    Tried this...but it´s not working

    $items[] = l($account->name, 'user/'.$account->uid, $object->uid, array('title' => t('View user profile'), 'class' => $class)); 
    
    erika’s picture

    Thanks msolt...
    This'll be very helpful for newbies...

    msolt’s picture

    I hope so.
    The problem is that there is one, little bug. I´ll try to fix (maybe someone knows how to fix it).
    When it´s done I´ll change the script above ;-)

    Best regards,
    Maik

    coreb’s picture

    Congratulations on solving this. There were alot more bugs than I thought.

    I have a fix for the bug you found. Looking at the code you last posted:

    $items[] = l($account->name, 'user/'.$account->uid, $object->uid, array('title' => t('View user profile'), 'class' => $class));
    

    Change it to:

    $items[] = l($account->name, 'user/'.$account->uid, array('title' => t('View user profile'), 'class' => $class));
    

    I copy/pasted that code from somewhere else, but forgot to update to change the variable name from $object to $account.

    I've found another "bug", although I'm not sure this piece of code get executed. It depends on the way your site is setup.

     else {
             $items[] = '<span style="' . $style . '">' . check_plain($account->name) . '</style>';
         } 
    

    should be

     else {
             $items[] = '<span class="' . $class . '">' . check_plain($account->name) . '</span>';
         } 
    
    msolt’s picture

    Great work again coreb...
    thank you very much, if u will need help please let me know...I will do my best, to help YOU!

    For all who want to use this snippet, here´s the updated Version:

    $number = db_result(db_query('SELECT COUNT(uid) AS number FROM {users} WHERE status=1'));
    
            if (user_access('access content')) {
              // Count users with activity in the past defined period.
              $time_period = variable_get('user_block_seconds_online', 900);
    
              // Perform database queries to gather online user lists.
             $users = db_query('SELECT u.uid, u.name, access, v.value as profile_gender  FROM {users} u, {profile_fields} f, {profile_values} v WHERE access >= %d AND u.uid != 0 AND u.uid=v.uid AND f.fid=v.fid AND f.name=\'profile_gender\' ORDER BY access DESC', time() - $time_period);
    
              $total_users = db_num_rows($users);
    
       
              // Display a list of currently online users.
           $max_users = variable_get('user_block_max_list_count', 10); 
    if ($total_users && $max_users) {
      $items = array();
      while ($max_users-- && $account = db_fetch_object($users)) {
         
    $class = "";
        if (strcasecmp(substr($account->profile_gender,0,1),"M") == 0)
             $class = "boyuser";
    else if (strcasecmp(substr($account->profile_gender,0,1),"F") == 0)
             $class = "girluser"; 
    
             if (user_access('access user profiles')) { 
            $items[] = l($account->name, 'user/'.$account->uid, array('title' => t('View user profile'), 'class' => $class));
         } 
         else {
             $items[] = '<span class="' . $class . '">' . check_plain($account->name) . '</span>';
         } 
    }
         $output .= theme('item_list', $items, t('Online users')); 
      
    }
    } 
    return $output; 
    
    fe’s picture

    how can i show the user pictures next to the users name?

    royal007’s picture

    I am trying to do something similar.

    But I want to keep the standard drupal "who's online" block that says

    There are currently 2 users and 0 guests online.
    Online users

    * testuser-female
    * testuser-male

    * is the default icon (that comes with the theme i am using)

    All I want is for the female/male users to have different icons from the default icon (the default icon still needs to be used for those that do not enter a gender). I am using the profile with profile_gender set to male or female. This all sounds very simple but I don't know where to find the "who's online" php code and also haven't the faintest idea what code to put in there (would snippets from the codes posted on here work, I don't need the colors of the users changed). Anyone know if this can be done?? any help would be grateful. thanks

    erika’s picture

    hi ,

    I've seen the code snippet in the forum.All i remember is te period in which it wa posted.It was between May 15 th and june 15 th.
    try your luck
    all the best