The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
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. |
#2
|
|||
|
|||
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']; } |
#3
|
||||
|
||||
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 ? |
#4
|
|||
|
|||
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:
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). |
#5
|
|||
|
|||
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.
|
#6
|
||||
|
||||
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: |
#7
|
|||
|
|||
Hmm...you may need to add "global $vbulletin;" to the beginning to use it in a forum block.
|
#8
|
||||
|
||||
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']; } |
#9
|
|||
|
|||
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. |
#10
|
||||
|
||||
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; } |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|