Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 12-30-2010, 10:48 PM
Hornstar Hornstar is offline
 
Join Date: Jun 2005
Location: Australia
Posts: 2,469
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default list all users of a usergroup

How would I list all users from a usergroup?
Reply With Quote
  #2  
Old 12-30-2010, 11:11 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 12-30-2010, 11:24 PM
Hornstar Hornstar is offline
 
Join Date: Jun 2005
Location: Australia
Posts: 2,469
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 12-31-2010, 12:21 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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).
Reply With Quote
  #5  
Old 12-31-2010, 12:38 AM
Hornstar Hornstar is offline
 
Join Date: Jun 2005
Location: Australia
Posts: 2,469
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

[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.
Reply With Quote
  #6  
Old 12-31-2010, 12:46 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 View Post
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.
Reply With Quote
  #7  
Old 12-31-2010, 12:56 AM
Hornstar Hornstar is offline
 
Join Date: Jun 2005
Location: Australia
Posts: 2,469
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 12-31-2010, 12:57 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

Quote:
Originally Posted by Hornstar View Post
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.
Reply With Quote
  #9  
Old 12-31-2010, 01:00 AM
Hornstar Hornstar is offline
 
Join Date: Jun 2005
Location: Australia
Posts: 2,469
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #10  
Old 12-31-2010, 01:48 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 View Post
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...
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:13 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07500 seconds
  • Memory Usage 2,292KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (4)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete