Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-02-2014, 10:17 AM
Davey-UK's Avatar
Davey-UK Davey-UK is offline
 
Join Date: Feb 2003
Location: Sheffield-UK
Posts: 244
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Total Users In Usergroup

Hello all.
Could anyone point me in the right direction, as to how to show the total number of members in a certain usergroup in a sidebar module and/or on the forumhome.

If it helps, the usergroup number is 12.

Thanks a bunch.
Reply With Quote
  #2  
Old 02-02-2014, 11:13 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, you could do this:
Code:
if ($result = $vbulletin->db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "user WHERE usergroupid = 12"))
{
      $num_members = $result['count'];
}
Then either pre-register $num_members to a template where you want to use it, or else create a php type block and return some html that includes that variable.
Reply With Quote
  #3  
Old 02-02-2014, 11:53 AM
Davey-UK's Avatar
Davey-UK Davey-UK is offline
 
Join Date: Feb 2003
Location: Sheffield-UK
Posts: 244
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Mmm, thanks i will give it a whirl.
Do you mean add the text you have added as a plugin, then make a new template which can be called via $num_members ?
Reply With Quote
  #4  
Old 02-02-2014, 12:14 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you want to make a forum block, then you can make a php type block and use that code as part of it. If you want to put the value in an existing template, then you need to create a plugin, use that code, and also add a line to pre-register it to the template you want it to display in (and also edit the template to add something like {vb:raw num_members}).

For example, if you wanted to add it somewhere in the FORUMHOME template, you could create a plugin using hook location forumhome_complete and code like this:
PHP Code:
if ($result $vbulletin->db->query_first("SELECT COUNT(*) AS count FROM " TABLE_PREFIX "user WHERE usergroupid = 12"))
{
      
$num_grp_members $result['count'];
      
vB_Template::preRegister('FORUMHOME', array('num_grp_members' => $num_grp_members));


Then in FORUMHOME, something like:
Code:
<vb:if condition="isset($num_grp_members)">There are {vb:raw num_grp_members} in group 12</vb:if>

BTW, you wouldn't expect that query to fail, but it's good to check anyway and do something reasonable rather than display 0.

(I changed it to use num_grp_members because I think num_members might be used already).
Reply With Quote
  #5  
Old 02-02-2014, 12:30 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh, I also meant to mention: that query only works if 12 is the users' primary usergroup. If you're using it as a secondary group it needs to be modified to check the membergroups column.
Reply With Quote
  #6  
Old 02-02-2014, 12:41 PM
Davey-UK's Avatar
Davey-UK Davey-UK is offline
 
Join Date: Feb 2003
Location: Sheffield-UK
Posts: 244
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Fabulous!! Thankyou. That works great on Forum Home.
I tried the code in a php block, but it causes a white screen of nothingness on the forum.

Not my forte unfortunately.

Thankyou though, i have a starting block at least. :up:
Reply With Quote
  #7  
Old 02-02-2014, 12:43 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm...you may need to add "global $vbulletin;" to the beginning to use it in a forum block.
Reply With Quote
  #8  
Old 02-02-2014, 12:47 PM
Davey-UK's Avatar
Davey-UK Davey-UK is offline
 
Join Date: Feb 2003
Location: Sheffield-UK
Posts: 244
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Strange.
I added
Code:
if ($result = global $vbulletin->db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "user WHERE usergroupid = 12"))
{
      $num_grp_members = $result['count'];
}
to a forum block, and it does stop the white screen, but the block doesn't show at all.
Reply With Quote
  #9  
Old 02-02-2014, 12:51 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry I wasn't clear, it should be:
Code:
global $vbulletin;
if ($result = $vbulletin->db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "user WHERE usergroupid = 12"))
{
      $num_grp_members = $result['count'];
}

But you also need to return some html to see anything.
Reply With Quote
  #10  
Old 02-02-2014, 12:58 PM
Davey-UK's Avatar
Davey-UK Davey-UK is offline
 
Join Date: Feb 2003
Location: Sheffield-UK
Posts: 244
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes that works, but still not showing the number in sideblock. Would this be correct?
Code:
global $vbulletin;
if ($result = $vbulletin->db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "user WHERE usergroupid = 12"))
{     
$output =  "We currently have" . $num_grp_members . "<br />" . "<a href=http://www.mysite.com/forum/payments.php> Upgrade now</a>";

return $output; 
}
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 09:57 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.04228 seconds
  • Memory Usage 2,256KB
  • 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
  • (5)bbcode_code
  • (1)bbcode_php
  • (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_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