List of user profiles for a given role
Last modified: February 28, 2009 - 19:48
** Users interested in a Drupal 6.x compatible version of this snippet may want to investigate installing the views.module and create a view that will accomplish this task.
The following page snippet gives a list of users from a particular role, in the style of a usual profile listing.
Drupal 5.x:
<?php
//choose the role to list by value.
// Note ID 1 = anonymous, ID 2 = authenticated user
// so valid values here are > 2.
$rid = 4;
?>
<?php
$fields = array();
$result = db_query('SELECT name, title, type, weight FROM {profile_fields} ORDER BY category DESC, weight');
while ($record = db_fetch_object($result)) {
$fields[] = $record;
}
$result = pager_query("SELECT u.uid, u.name, u.status, u.created, u.access FROM {users} u INNER JOIN {users_roles} ur ON u.uid=ur.uid WHERE ur.rid = $rid ORDER BY access DESC", 20, 0, NULL);
$status = array(t('blocked'), t('active'));
$output = '<div id="profile">';
while ($account = db_fetch_object($result)) {
$account = user_load(array('uid' => $account->uid));
$profile = _profile_update_user_fields($fields, $account);
$output .= theme('profile_listing', $account, $profile);
}
$output .= '</div>';
$output .= theme('pager', NULL, 20);
print ($output);
?>Drupal 4.7.x:
<?php
//choose the role to list by value.
// Note ID 1 = anonymous, ID 2 = authenticated user
// so valid values here are > 2.
$rid = 4;
$fields = array();
$result = db_query('SELECT name, title, type, weight FROM {profile_fields} WHERE visibility = %d ORDER BY category DESC, weight', PROFILE_PUBLIC_LISTINGS);
while ($record = db_fetch_object($result)) {
$fields[] = $record;
}
$result = pager_query("SELECT u.uid, u.name, u.status, u.created, u.access FROM {users} u INNER JOIN {users_roles} ur ON u.uid=ur.uid WHERE ur.rid = $rid ORDER BY access DESC", 20, 0, NULL);
$status = array(t('blocked'), t('active'));
$output = '<div id="profile">';
while ($account = db_fetch_object($result)) {
$account = user_load(array('uid' => $account->uid));
$profile = _profile_update_user_fields($fields, $account);
$output .= theme('profile_listing', $account, $profile);
}
$output .= '</div>';
$output .= theme('pager', NULL, 20);
print ($output);
?>For a table-type list, see http://drupal.org/node/63422
