Hey I just am stuck trying to work out how to get this php db query to work and I can not see why.
I am useing a CMS system which is drupal and I want to display the users that are online right now and there role on the website Admin, mod etc.
This is what I have done.
I can get the roles with
CODE
$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 = "";
}
The code above works to display all the admins but just the ones online which I would like.
I tryed writeing an sql query to do this but it does not work which is.
CODE
<?php
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);
?>
There are 4 roles that I wish to displays rid 3 to rid 6.
I am 100% sure that the if statment is correct but I know the select query is not which is where I am stuck with what is wrong.
This post has been edited by skyhawk133: 5 Jul, 2007 - 06:56 AM