Customizing SMF > SMF Coding Discussion

Count the users inside a spesific membergroup

(1/2) > >>

ara_is_sweet:
I have searched and searched for this, but I couldn't find any info regarding this other then it's a heavy query(?)  :(
There dosent seem like there is any function that does this, even though its done in the admin area.

I need a function in my SSI that can paste the number of members of visible membergroups.

I.e: Admin group : 2

 If anyone can help me out, it would be awsome! PS: im a php nub!

Yoshi:
Hi ara_is_sweet!

Heavy query? Where?

If you know the ID of the membergroup:


--- Code: ---$result = $smcFunc['db_query']('', '
SELECT id_member
FROM {db_prefix}members
WHERE id_group = {int:group}',
array(
'group' => 'the ID of the group'
));

$num_users = $smcFunc['db_num_rows']($result);
--- End code ---

That's all.

EDIT: Forgot the $smcFunc skin for the db_num_rows.

ara_is_sweet:
Hey, and thanks for the fast reply. Yes, I know the ID, but how do I call the function?


--- Code: ---<?php 
echo'' , $result['num_users'] , '';
?>
--- End code ---
Something like this? Sorry, but I'm new to php :(

Arantor:
That won't work if you have any users who have that group as a secondary group, or if it's a post-count based group.

What you actually need to do is (and this is also faster than actually getting all the names, too):


--- Code: ---$result = $smcFunc['db_query']('', '
SELECT COUNT(id_member)
FROM {db_prefix}members
WHERE id_group = {int:group} OR id_post_group = {int:group} OR FIND_IN_SET({int:group}, additional_groups)'',
array(
'group' => 'the ID of the group'
));

list($num_users) = $smcFunc['db_fetch_row']($result);
--- End code ---

To do something with the number afterwards, simply:

--- Code: ---echo $num_users;
--- End code ---

ara_is_sweet:
Thanks a lot guys!    ;D

That did the trick. (Btw, there seems to be a ' too much?)

Navigation

[0] Message Index

[#] Next page

Go to full version