How to list all users in a specific group?

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
User avatar
SineMacula
Joomla! Explorer
Joomla! Explorer
Posts: 453
Joined: Sun Aug 21, 2005 5:16 am
Location: San Jose, CA
Contact:

How to list all users in a specific group?

Post by SineMacula » Fri Apr 06, 2012 7:54 pm

How can I make a list of all users (names) who belong to a specific group?

Specifically, I want to create a select form field with all users of a group listed - and I'm thinking it might make sense to have the names listed, but the values be the userid.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30888
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: How to list all users in a specific group?

Post by Per Yngve Berg » Fri Apr 06, 2012 8:48 pm


User avatar
SineMacula
Joomla! Explorer
Joomla! Explorer
Posts: 453
Joined: Sun Aug 21, 2005 5:16 am
Location: San Jose, CA
Contact:

Re: How to list all users in a specific group?

Post by SineMacula » Fri Apr 06, 2012 9:01 pm

Thanks... but I don't think that's quite what I'm looking for - it looks to me like the link you provided deals with getting all the groups of a specific user, whereas I need to know how to get all the users for a specific group.

I did figure out that I can get the list I need this way:

Code: Select all

jimport( 'joomla.access.access' );
$coaches = JAccess::getUsersByGroup(9);
But, I don't know how to go from that to getting a list of names of those users (it seems to just get the ids)... and then to be able to list the names as select field options (with ids as the field values).

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30888
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: How to list all users in a specific group?

Post by Per Yngve Berg » Fri Apr 06, 2012 9:21 pm


User avatar
SineMacula
Joomla! Explorer
Joomla! Explorer
Posts: 453
Joined: Sun Aug 21, 2005 5:16 am
Location: San Jose, CA
Contact:

Re: How to list all users in a specific group?

Post by SineMacula » Fri Apr 06, 2012 11:09 pm

Okay, thanks... so, when I tried 'load' I got an error (it appears to be because I'm doing this as php and javascript files loaded into Joomla pages via the Jumi component, but I'm not sure)... but that lead me to this:

Code: Select all

jimport( 'joomla.access.access' );
$coaches = JAccess::getUsersByGroup(9);
jimport( 'joomla.user.user' );
foreach($coaches as $coaches){
$coach[$coaches] =& JFactory::getUser($coaches);
}
...and then...

Code: Select all

<label>Coach:</label>
<select name="coachId">
<?php foreach($coach as $coach){ ?>
<option value="<?php echo $coach->id; ?>"><?php echo $coach->name; ?></option>
<?php } ?>
</select>
It appears to be working! (Well, at least I've got the select pulldown... we'll see if I can take it the next step to get the data I want from this later in the process of my 'app'.)

Thanks for your help!


Locked

Return to “Joomla! 2.5 Coding”