Ok I would like to work if they are online and there role.
I would out how to list the roles with the code here.

<?php
print "<br>3";
$rid3 = 3;
$result = db_query("SELECT u.uid, u.name, u.status FROM {users} u
INNER JOIN {users_roles} ur ON u.uid=ur.uid WHERE ur.rid = %d
AND u.status = 1", $rid3);
while ($u = db_fetch_object($result)) {
  $items[] = l($u->name, "user/" . $u->uid);
}
print theme('item_list', $items);
$items = "";
print "<br>4";
$rid4 = 4;
$result = db_query("SELECT u.uid, u.name, u.status FROM {users} u
INNER JOIN {users_roles} ur ON u.uid=ur.uid WHERE ur.rid = %d
AND u.status = 1", $rid4);
while ($u = db_fetch_object($result)) {
  $items[] = l($u->name, "user/" . $u->uid);
print theme('item_list', $items);
$items = "";
}
print "<br>5";
$rid5 = 5;
$result = db_query("SELECT u.uid, u.name, u.status FROM {users} u
INNER JOIN {users_roles} ur ON u.uid=ur.uid WHERE ur.rid = %d
AND u.status = 1", $rid5);
while ($u = db_fetch_object($result)) {
  $items[] = l($u->name, "user/" . $u->uid);
print theme('item_list', $items);
$items = "";
}
print "<br>6";
$rid6 = 6;
$result = db_query("SELECT u.uid, u.name, u.status FROM {users} u
INNER JOIN {users_roles} ur ON u.uid=ur.uid WHERE ur.rid = %d
AND u.status = 1", $rid6);
while ($u = db_fetch_object($result)) {
  $items[] = l($u->name, "user/" . $u->uid);
print theme('item_list', $items);
$items = "";
}
?>

Now I need to only display them if they are online in a session am losted how to do this with the sql.
If someone has the time would they mind helping me please.

Comments

Tistur’s picture

Did you look at user.module (under user_block, about line 577 in 5.1)?

Also, is there a reason you're not using an array of role ids and looping through? Having so much repetitiveness could get very hairy if you need to change something.

CreativeMe’s picture

I have looked at that code yes
This is where I am at now.
[code]

print "Online Admin";
$rid3 = 3;
if (user_access('access content')) {
          // Count users with activity in the past defined period.
          $time_period = variable_get('user_block_seconds_online', 900);
		  
$result = db_query('
SELECT u.uid, u.name, u.status, u.access FROM (users) u INNER JOIN (users_roles) ur ON u.uid = ur.uid WHERE u.access >= %d AND u.uid != 0 AND ur.rid = %d AND u.status = 1 ORDER BY access DESC',time() - $time_period, $rid3);
while ($u = db_fetch_object($result)) {
  $items[] = l($u->name, "user/" . $u->uid);

[/code]
I can not see where I have gone wrong?

I get this error Parse error: syntax error, unexpected $end in C:\xampplite\htdocs\d\includes\common.inc(1342) : eval()'d code on line 24

vm’s picture

your parse error could be because you don't use any closing }'s

Tistur’s picture

I've been using something like this, but I'm not sure how a 3-way INNER JOIN would work.

    $interval = time() - (600);
    // Perform database queries to gather online user lists.  We use s.timestamp rather than u.access because it is much faster is much faster..
    $active_users = db_query('SELECT u.uid, u.name FROM{users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= %d AND s.uid > 0  AND u.status != 0 ORDER BY s.timestamp DESC', $interval);
    while ($account = db_fetch_object($active_users)) {
        // etc....

CreativeMe’s picture

I had a go at making the 3-way INNER JOIN but could not get it to work

[code]

print "Online rid 3";
$rid3 = 3;
$interval = time() - (600);
$active_users = db_query('SELECT u.uid, u.name FROM (users) u INNER JOIN (sessions) s ON (u.uid = s.uid) INNER JOIN (User_roles) ur ON (u.uid = ur.rid) WHERE ur.rid = 3 AND s.timestamp >= %d AND s.uid > 0  AND u.status != 0 ORDER BY s.timestamp DESC', $interval);
    while ($account = db_fetch_object($active_users)) {
        $active_users[] = l($u->name, "u.user/" . $u->u.uid);}

[/code]

Unsure where I have gone wrong with this.

Tistur’s picture

You've probably found a better solution, but this seems to work for me (for future readers). It's extraordinarily wasteful and slow, but it works.

function _test_many_select(){
if (user_access('access content')) {
	$interval = time() - (5) * 60);

	$users = db_query('SELECT u.name, u.uid, ur.rid FROM {users_roles} ur, {users} u WHERE u.uid IN (SELECT s.uid FROM {sessions} s WHERE timestamp >= %d) AND ur.uid = u.uid ORDER BY ur.rid', $interval);
	
	while ($u = db_fetch_object($users)) {
		$user_links[$u->uid] = l($u->name, "user/" . $u->uid);
		$people[$u->rid][$u->uid] = & $user_links[$u->uid];
	}

	$roles = db_query('SELECT * FROM {role} WHERE rid > %d',2); 
	
	while($r = db_fetch_object($roles)){
		$output .= '<b>'. $r->name .'</b>:<br>';
		foreach( $people[$r->rid] as $uid => $person) {
			$output .= $person .'<br>';
		}
	}
  }
	return	$output;
}
Anonymous’s picture

i am looking for a similar solution to see who's online as the default drupal 7 block is lacking some features.

I tried your code and it doesen't seem to work.