Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-28-2008, 08:09 PM
lasto lasto is offline
 
Join Date: Jan 2002
Posts: 1,514
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Usergroups

Say i have 20 users in one usergroup - how can i call the amount of users in one specific usergroup so i can use that info on my index.php page.

I just want to grab the amount of users in one specific usergroup and display the info on main page so it looks something like this :

Admins : 7 (if that is the correct number)

Is this possible ......

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

anyone know a way to pull this off - i know its not a big request
Reply With Quote
  #2  
Old 03-30-2008, 06:46 AM
lasto lasto is offline
 
Join Date: Jan 2002
Posts: 1,514
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

/me bumps this again
Reply With Quote
  #3  
Old 03-30-2008, 11:33 AM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Check the Usergroup.php page in the AdminCP to see how vBulletin does it.

I'm not sure if the count is stored in the usergroup cache, (run a var_dump() of $vbulletin->usergroupcache to see if it is present).

If it doesn't then you best bet is to run a query to count the users in each usergroup and run this on the usergroup.php page or as a scheduled task to update a cache in the datastore. (You don't want to be querying the database on every page load when the data is going to be fairly static).

I'll see if I can give you some more information later, when I boot up my dev vBulletin, but this should give you an idea of what to do/look for.
Reply With Quote
  #4  
Old 03-30-2008, 04:37 PM
lasto lasto is offline
 
Join Date: Jan 2002
Posts: 1,514
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

cheers m8 as all i want the code for is to call on index.php to show how many users are in one particular usergroup.
Reply With Quote
  #5  
Old 03-30-2008, 05:15 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm by the looks of it, it isn't stored in the usergroup cache. Here is the query I pulled from the usergroup admin page:
PHP Code:
    // count primary users
    
$groupcounts $db->query_read("
        SELECT user.usergroupid, COUNT(user.userid) AS total
        FROM " 
TABLE_PREFIX "user AS user
        LEFT JOIN " 
TABLE_PREFIX "usergroup AS usergroup USING (usergroupid)
        WHERE usergroup.usergroupid IS NOT NULL
        GROUP BY usergroupid
    "
); 
You could change the WHERE clause to select just what you want.

Have a read of this as you'll probably just want to cache the results to save on queries and processing time. Cache System Explanation (datastore)
Reply With Quote
  #6  
Old 03-30-2008, 06:38 PM
lasto lasto is offline
 
Join Date: Jan 2002
Posts: 1,514
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

bit to much for me m8 how can i use the above info to show the stat i want without it sounding to over complicated

and thanks as well
Reply With Quote
  #7  
Old 03-31-2008, 05:19 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The simple way, without using the cache (bad for load-heavy sites, and bad in general coding practise!):
PHP Code:
// count users in usergroup 7 (primary usergroups only)
$groupcount $vbulletin->db->query_read("
    SELECT COUNT(userid)
    FROM " 
TABLE_PREFIX "user
    WHERE usergroupid = 7
"
);
$groupcount $groupcount['userid']; 
Reply With Quote
  #8  
Old 03-31-2008, 03:00 PM
lasto lasto is offline
 
Join Date: Jan 2002
Posts: 1,514
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i would add that code to my index.php is that correct : now what code would i need to call it into the board
Reply With Quote
  #9  
Old 03-31-2008, 04:17 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Put that code in a FORUMHOME hook. Like forumhome_complete or something like that.

Then you just need to add $groupcount in your FORUMHOME template. Like:
Code:
Adminstrator: $groupcount
Reply With Quote
  #10  
Old 04-01-2008, 03:51 AM
lasto lasto is offline
 
Join Date: Jan 2002
Posts: 1,514
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks m8 will try this tonight when get back from work.
Reply With Quote
Reply


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 05:09 PM.


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.04215 seconds
  • Memory Usage 2,249KB
  • Queries Executed 11 (?)
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
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (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_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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete