List Users From a Single Role in a Block

Drupal

Drupal

An open-source content management system that is used on this site and is taking over the world. 4.7.x - taken from Drupal site

Using a similar SQLStructured Query Language - a language for accessing a database. statement found in a page display of users by a certain role, Drupal

Drupal

An open-source content management system that is used on this site and is taking over the world. can generate a block listing users and linking to their user profiles. This might be useful if you want to list a few users, such as an editorial team, in a block and not have to edit HTMLHyperText Markup Language - the coding standard for a web page. each time to create that list. Replace the number 3 with the ID of the role you wish to display users from. You can find out the IDs of roles by going to administer » access control » roles tab and clicking the "edit" linkThe technique which points to another page, anywhere on the Internet, from the current page.. The ID appears at the end of the resulting URL.

Put this in a custom block (administer » blocks » add block tab) and be sure to select the "PHPRecursive acronym for "PHP: Hypertext Preprocessor" - is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. code" input format.

<?php
  $rid
= 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"
, $rid);while ($u = db_fetch_object($result)) {
      
$items[] = l($u->name, "user/" . $u->uid);
    }
  return
theme('item_list', $items);
?>

To list the users alphabetically, use the following, slightly-modified code:

<?php
  $rid
= 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 ORDER BY u.name ASC"
, $rid);
  while (
$u = db_fetch_object($result)) {
   
$items[] = l($u->name, "user/" . $u->uid);
    }
  return
theme('item_list', $items);
?>

Change "ASC" to "DESC" if you want the list reverse-alphabetical.

Final, Working Version

<P>This page is intended to give you an introduction to the Board of Directors.</P>
<P>The BOD conducts the business of Kappa Beta, such as securing a meeting room, reserving a dinner venue, and planning the annual Christmas party, to name a small part of it. They are not dictators. According to the Bylaws, they are supposed to lead by example. The BOD implements things, but the membership sets the direction by discussion and voting. Click here for more on <A HREF="WhatGood">What Good is the Board</A>.</P>

<?php
$rid
= 5;

print(
"<table><caption><b>The Board Members</b></caption>\n");

$header = array(
  array(
'data' => t('Username'), 'field' => 'u.name', 'sort' => 'asc'),
  array(
'data' => t('Photo')),
  array(
'data' => t('Name')),
  array(
'data' => t('Current Pos')),
  array(
'data' => t('CV')),
  array(
'data' => t('Member since'))
);

$sql = "SELECT u.uid, u.name FROM {users} u INNER JOIN {users_roles} ur ON u.uid=ur.uid WHERE ur.rid = $rid";
$sql .= tablesort_sql($header);
$result = pager_query($sql, 50);

while (
$account = db_fetch_object($result)) {
  
$account = user_load(array('uid' => $account->uid));
   if(
$account->picture){$account->picture = '<img src="/'.$account->picture.'" height="100" width="100" border="0" alt="'.$account->name.'">';}
     else{
$account->picture = '<img src="/files/pictures/KB/bodYou.gif" height="100" width="100" border="0" alt="no picture found">';}

print(
'<tr><td align="center">' . $account->picture . "<br>"
     
. $account->profile_firstname . " " . $account->profile_lastname
     
. '</td><td align="center"><b>' . $account->profile_currentboard . "</b>"
     
. "</td>\n<td>Member since " . date('F Y', mktime(0, 0, 0, $account->profile_date_joined['month'],
                                     
$account->profile_date_joined['day'],
                                     
$account->profile_date_joined['year']))
      .
". " . $account->profile_cv
     
. "</td></tr> \n");
}

print(
"</table>\n");
?>

Customising the user profile layout

Customising the user profile layout

The PHPRecursive acronym for "PHP: Hypertext Preprocessor" - is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. Snippets below are intended for use within a customised USER PROFILE page that simply enables you to "pull" specific content from your drupal

Drupal

An open-source content management system that is used on this site and is taking over the world. databaseA collection of data related to an application. specific to a particular user and display it in the way you want.

They are intended for use with a phptemplate based themeFor web sites, this refers to the "look and feel" of the site. It is also used to describe the code to produce that look. and for Drupal

Drupal

An open-source content management system that is used on this site and is taking over the world. siteA logically grouped set of content - also web site. developers who do not have phpRecursive acronym for "PHP: Hypertext Preprocessor" - is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. programming knowledge but want to push out the boundaries of user profile pages and control precisely how they look.

Simple step-by-step instructions are provided.

Custom User Blocks and User Tables PHP Snippets