Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,664 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,164 people online right now. Registration is fast and FREE... Join Now!




Trying to Get Online Users - Drupal

 
Reply to this topicStart new topic

Trying to Get Online Users - Drupal

Creative
post 4 Jul, 2007 - 05:59 PM
Post #1


New D.I.C Head

*
Joined: 26 Jun, 2007
Posts: 12


My Contributions


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
User is offlineProfile CardPM

Go to the top of the page

Creative
post 4 Jul, 2007 - 06:12 PM
Post #2


New D.I.C Head

*
Joined: 26 Jun, 2007
Posts: 12


My Contributions


Sorry maybe its easyer if I show working code to display all users online.

CODE

<?php
$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.
          $guests = db_fetch_object(db_query('SELECT COUNT(sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0', time() - $time_period));
          $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);
          // Format the output with proper grammar.
echo "Out of $number registered users ";
          if ($total_users == 1 && $guests->count == 1) {
            $output = t('%members and %visitors online.', array('%members' => format_plural($total_users, 'there is currently 1 user', 'there are currently @count users'), '%visitors' => format_plural($guests->count, '1 guest', '@count guests')));
          }
          else {
        $output = t('there are currently %members and %visitors online.', array('%members' => format_plural($total_users, '1 user', '@count users'), '%visitors' => format_plural($guests->count, '1 guest', '@count guests')));
          }
          // 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;
?>


This post has been edited by Creative: 4 Jul, 2007 - 06:13 PM
User is offlineProfile CardPM

Go to the top of the page

Creative
post 5 Jul, 2007 - 05:43 AM
Post #3


New D.I.C Head

*
Joined: 26 Jun, 2007
Posts: 12


My Contributions


I had a go at making the 3-way INNER JOIN but it does not work so what am i doing wrong?

CODE

print "Online Admin";
$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);// Errors on the query
    while ($account = db_fetch_object($active_users)) {
        $active_users[] = l($u->name, "u.user/" . $u->u.uid);
        }

User is offlineProfile CardPM

Go to the top of the page

capty99
post 5 Jul, 2007 - 06:08 AM
Post #4


the real kya

Group Icon
Joined: 26 Apr, 2001
Posts: 9,137



Thanked 15 times

Dream Kudos: 550
My Contributions


hey creative,
welcome to the site,

if you don't get an answer by this afternoon i would suggest heading over to the drupal forums and try there. normally this would be your best resource but because your using their cms they really are the most knowledgable and only a handful of our guys have probably used it before.

by tonight everyone should have had a look at it...
User is offlineProfile CardPM

Go to the top of the page

Creative
post 5 Jul, 2007 - 06:47 AM
Post #5


New D.I.C Head

*
Joined: 26 Jun, 2007
Posts: 12


My Contributions


Thanks for the reply Tyler James Lee
And I understand what you are saying but they are not alot of help.
http://drupal.org/node/156820#comment-248860
And althought its there DB and cms its all the same mysql code that it is working on which is where I am stuck.
User is offlineProfile CardPM

Go to the top of the page

capty99
post 5 Jul, 2007 - 06:54 AM
Post #6


the real kya

Group Icon
Joined: 26 Apr, 2001
Posts: 9,137



Thanked 15 times

Dream Kudos: 550
My Contributions


yeah, but if i remember correctly drupal and joomla both have interesting ways of going about organizing some things and naming etc... its reflected in the code.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 05:46AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month