Hi,

I created a view that displays a table of users.

I want to limit the output to a specific list of usernames that the view should get as argument.

How do I do that?

Comments

gurubert’s picture

Hi,

I found a solution that works for me by converting usernames into user IDs and passing them as argument to the view.


function view_usernames($input) {

  static $output = array();

  if (! $output[$input]) {

    $usernames = explode(",", $input);

    $query = "SELECT u.uid FROM {users} u WHERE name in ('". implode("', '", array_fill(0, sizeof($usernames), "%s")) ."')";

    $result = db_query($query, $usernames);

    $userids = array();

    while ($user = db_fetch_object($result)) {

      $userids[] = $user->uid;

    }

    $userlist_view = views_get_view('userlist');

    $output[$input] = $userlist_view->execute_display(0, array(implode(",", $userids)));
  }

  return $output[$input];
}

The view needs an argument of type "User: Uid" which accepts multiple values.

merlinofchaos’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.