vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   list all users of a usergroup (https://vborg.vbsupport.ru/showthread.php?t=256215)

Hornstar 12-30-2010 10:48 PM

list all users of a usergroup
 
How would I list all users from a usergroup?

kh99 12-30-2010 11:11 PM

I think you just need to use "Search For Users" (under Users in the ACP), and choose the group you want from the drop-down menu.

Hornstar 12-30-2010 11:24 PM

I was a bit vauge sorry. I meant how would I list all users from a usergroup on a template/page.

eg. I have created a file called users.php and a template called users.

I want to list all users from usergroup x, y z like this on the page users.php:
Usergroup x: user 1, user 2, user 3
usergroup y: user 1, user 2, user 3
usergroup z: user 1, user 2, user 3


My first thinking was there may be a variable?
Is there any variable which can list all users from a usergroup?

My second thinking was I need to query the users in the usergroup, and then display it. (I need help on the code for this part if so)

Thanks in advance.

kh99 12-31-2010 12:21 AM

OK, sorry - I guess that's why you posted in the Programming Discussion area.

Anyway, I think you want something like this:

PHP Code:

$groupid 1// set this to the group id you want
$users $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user
                   WHERE usergroupid = 
$groupid");
$str '';
$sep '';
while (
$user $vbulletin->db->fetch_array($users))
{
    
$str .= $sep $user['username'];
    
$sep ', ';
}
// $str is comma separated list of users in $groupid
$vbulletin->db->free_result($users); 


That does one user group, so you can put that whole thing in a loop, or you could modify the query to get all groups at once and handle the separate lists in the while loop.

Also this only handles primary user groups and not membership in secondary groups. (And also I haven't tried this code at all).

Hornstar 12-31-2010 12:38 AM

[strike]Yeah that does look like something I would need. However I can't get it to function just yet.
Maybe I am doing something wrong. Any chance you could test it out (also output 2 usergroups).
Thanks again.[/strike]


Edit: Got it to work with 1 usergroup now (So big thanks for that)
PHP Code:

$groupid 5// set this to the group id you want
$users $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user
                   WHERE usergroupid = 
$groupid");
$str '';
$sep '';
while (
$user $vbulletin->db->fetch_array($users))
{
    
$str .= $sep $user['username'];
    
$sep ', ';
}
// $str is comma separated list of users in $groupid
$vbulletin->db->free_result($users);  
echo 
"Super Mods: $str"

However not sure which is the best way to get multiple usergroups listed. You mentioned "That does one user group, so you can put that whole thing in a loop, or you could modify the query to get all groups at once and handle the separate lists in the while loop."
Could you give me an example of that.

Also is there a way to get it to list people in both primary and secondary?

Thanks again.

kh99 12-31-2010 12:46 AM

I could do that. But I also remembered, what you want pretty much already exists in showgroups.php (like this: https://vborg.vbsupport.ru/showgroups.php)

Edit: posted this before I saw your edit above.

--------------- Added [DATE]1293763857[/DATE] at [TIME]1293763857[/TIME] ---------------

Quote:

Originally Posted by Hornstar (Post 2141603)
You mentioned "[/B][/COLOR]That does one user group, so you can put that whole thing in a loop, or you could modify the query to get all groups at once and handle the separate lists in the while loop."
Could you give me an example of that.

Thanks again.

An example of which way, the second one?

The first way is easier off the top of my head:

PHP Code:

$groups = array("Super Mods" => 5"Admins" => 6"Mods" => 7); // set this to the group id you want

foreach ($groups as $groupname => $groupid)
{
$users $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user
                   WHERE usergroupid = 
$groupid");
$str '';
$sep '';
while (
$user $vbulletin->db->fetch_array($users))
{
    
$str .= $sep $user['username'];
    
$sep ', ';
}
// $str is comma separated list of users in $groupid
$vbulletin->db->free_result($users);  
echo 
"$groupname$str <BR>";



but again I haven't tried it so hoepfully there aren't any syntax errors.

Hornstar 12-31-2010 12:56 AM

This is what I am trying to achieve on the page:

Usergroup 4: user1, user2, user 3 etc.

Usergroup 9: user2, user 6, user 8 etc.

So which method you feel will do the above best will be fine. If possible can you also get it to work with both primary and secondary usergorups.

Thanks again.

kh99 12-31-2010 12:57 AM

Quote:

So which method you feel will do the above best will be fine.
See above...

Quote:

Originally Posted by Hornstar (Post 2141603)
Also is there a way to get it to list people in both primary and secondary?

That might take a little while, I don't know how to do that offhand.

Hornstar 12-31-2010 01:00 AM

I missed your reply before, trying that now. one sec. Will edit this when I am done. Thanks.

Edit: yeah that worked great
Code:

$groups = array("Super Mods" => 5, "Admins" => 6, "Mods" => 7); // set this to the group id you want

foreach ($groups as $groupname => $groupid)
{
$users = $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user
                  WHERE usergroupid = $groupid"
);
$str = '';
$sep = '';
while (
$user = $vbulletin->db->fetch_array($users))
{
   
$str .= $sep . $user['username'];
   
$sep = ', ';
}
// $str is comma separated list of users in $groupid
$vbulletin->db->free_result($users); 
echo
"$groupname: $str <BR></BR>";



The only improvement would be to have it work with both primary and secondary.

Gotta say tho, you have been really great :)

If you work out how to get it to work with primary and secondary you will be legendary.

Thanks again.

kh99 12-31-2010 01:48 AM

OK, it turned out to be pretty easy (thanks to the code in showgroups.php):

PHP Code:

$groups = array("Super Mods" => 5"Admins" => 6"Mods" => 7); 

foreach (
$groups as $groupname => $groupid

$users $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user 
                   WHERE usergroupid = 
$groupid OR FIND_IN_SET($groupid, membergroupids)"); 
$str ''
$sep ''
while (
$user $vbulletin->db->fetch_array($users)) 

    
$str .= $sep $user['username']; 
    
$sep ', '

// $str is comma separated list of users in $groupid 
$vbulletin->db->free_result($users);   
echo 
"$groupname$str <BR></BR>"



I was thinking of trying to do it the other way so that it would be only one query, but really it's starting to get to the point where it would have been easier to start with showgroups.php. And as long as you're not putting this on your home page or anything, it probably won't make any difference.

Quote:

Originally Posted by Hornstar (Post 2141618)
If you work out how to get it to work with primary and secondary you will be legendary.


Well, not so much legendary, more like 'too much free time', but anyway...


All times are GMT. The time now is 01:11 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01267 seconds
  • Memory Usage 1,785KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (4)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete