Community Documentation

How to create a page that lists all users and profile fields

Last updated August 5, 2010. Created by Agileware on July 8, 2009.
Edited by johnv. Log in to edit this page.

Copied from this comment, http://drupal.org/node/144037#comment-555339

In Drupal 5, Views did not handle users at all. This feature was added to Views 2 with Drupal 6.

So to create a page in Drupal 5 that lists all users, image and their profile fields on your Drupal website you need to:
1. Create a new page
2. Insert the following page text as PHP code.
3. Make sure the input format is set to PHP

This code will list the users in name alphabetical order, 50 per page.

<?php
// Compile a list of fields to show.
$fields = array();
$result = db_query('SELECT name, title, type, weight FROM {profile_fields} WHERE visibility = %d ORDER BY category, weight', PROFILE_PUBLIC_LISTINGS);

while (
$record = db_fetch_object($result)) {
     
$fields[] = $record;
}

// v.fid = 1 is the include in member gallery checkbox
// If the field contains integer values use ORDER BY ABS(v.value) to force numeric sorting

//Change the 50 to display more or less users per page
$result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = 1 ORDER BY u.name, v.value ASC", 50, 0, NULL);

$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);

return
$output;
?>

Comments

Display All Public Profile Information

Thank you for this great tip! I just have one thing to add: If you want the new page to list the full public profile of each user (instead of just the user's userid and full name), then remove the "WHERE visibility = %d " phrase from the 4th line of the code above. So, your final fourth line should read:

$result = db_query('SELECT name, title, type, weight FROM {profile_fields} ORDER BY category, weight', PROFILE_PUBLIC_LISTINGS);

Just aq quick ask.

Hi just wondering would I would need to do to the code to get the title of values to show as well.
IE

Name: Donatello
DOB: 01/02/1982
Favorite pizza: Pepperoni

Don't got any out put from this code?

I have included the above code in one page content,
but i am not getting anything from this code....???

i want to get the current user's profile field values and also it should include the custom fields value in that page...

So can any one suggest me or help through this, bcz i am getting mad at this thing.!!!!

How to list only users with the same role?

How could this code be modified to only display the user info if the user role matches that of the user that is invoking the code? I need the capability for a logged in user to see a list of only those users with the same role permission that he/she has. How can I do this?

Did someone do this with

Did someone do this with views in d6? Need you custom Field handler?

Thank you for the code. I

Thank you for the code. I have enabled PHP and pasted it in, but I keep getting this error code on page:

Parse error: syntax error, unexpected T_STRING in /home/kctd/public_html/community/modules/php/php.module(74) : eval()'d code on line 4

What is the issue?

nobody click here