Hello Drupal Forums,
I have been busy trying to get my site working and everything all in place. I have been trying to get a sortable members list together so new visitors can find who is in my online community.
I have been using the following snippet to make it so far. My problem is this; I get a nice looking grid output of, (username, real_name, city, state, country, last access) the problem is the "username" and "last access" are the only fields that are able to sort by. What I need it to do is also sort by State, Country & Real_name. When I do click on those field header field names I get the following error:
[user warning: Unknown column 'u.realname' in 'order clause' 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 = 3 ORDER BY u.realname ASC LIMIT 0, 50 in /hsphere/local/home/myname/testservered.com/includes/database.mysql.inc on line 172.]
Following snippet php used:
<?php
//choose the role to list by value.
// Note ID 1 = anonymous, ID 2 = authenticated user
// so valid values here are > 2.
$rid = 3;
?>
<?php
$header = array(
array('data' => t('Username'), 'field' => 'u.name', 'sort' => 'asc'),
array('data' => t('Real_Name'), 'field' => 'u.realname'),
array('data' => t('City'), 'field' => 'u.city'),
array('data' => t('State'), 'field' => 'u.state'),
array('data' => t('Country'), 'field' => 'u.country'),
array('data' => t('Last access'), 'field' => 'u.access')
);
$sql = "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";
$sql .= tablesort_sql($header);
$result = pager_query($sql, 50);
$status = array(t('blocked'), t('active'));
while ($account = db_fetch_object($result)) {
$account = user_load(array('uid' => $account->uid));
$rows[] = array(theme('username', $account),
$account->profile_realname,
$account->profile_city,
$account->profile_state,
$account->profile_country,
$account->access ? t('%time ago', array('%time' => format_interval(time() - $account->access))) : t('never'));
}
$output = theme('table', $header, $rows);
$output .= theme('pager', NULL, 50, 0);
print ($output);
?> Any help would be great to accomplish this! Let me know what others have tried.
Thanks,
Brent