I have the following function that lists users on a site that can upload photos and the categories that their photos are tagged with:
/*
* Get list of users that have photos
*/
function _imagelist_display_users() {
$rid = variable_get('imagelist_upload_role',1);
$user_path = variable_get('imagelist_view_user','photos/user');
$term_path = variable_get('imagelist_view_vocabulary','photos/tags');
$output = '';
//create table headers
$header = array(
array('data' => t('User'), 'field' => 'u.name', 'sort' => 'asc'),
array('data' => t('Categories'))
);
//get list of users that have the designated role for uploading photos
$sql = "SELECT u.uid, u.name FROM users u INNER JOIN users_roles ur ON u.uid = ur.uid WHERE ur.rid = %d";
$sql .= tablesort_sql($header);
$result = db_query($sql, $rid);
while ($data = db_fetch_object($result)) {
//empty array of terms for next user
$terms_array = '';
//create link from user name that points to user gallery
$link = l($data->name,$user_path.'/'.$data->uid);
//for each user, get list of terms assigned to photos uploaded by the user
$sql_terms = "select distinct tn.tid from term_node tn inner join node n on tn.nid = n.nid where n.uid = %d";
$result_terms = db_query($sql_terms,$data->uid);
while ($data_terms = db_fetch_object($result_terms)) {