Hello! So I want to make a simple group member counter. For example, the layout would be like this w/o any special CSS/HTML.
Group Name #1 | 5 ♀ | 4 ♂ | 2 ⚧
Group Name #2 | 1 ♀ | 1 ♂ | 3 ⚧
Group Name #2 | 2 ♀ | 4 ♂ | 7 ⚧
Basically, I want to display the group's name, along with the number of members in each group according to their gender assigned on-site (regular + additions w/ more genders modification). Would there be any possible way to do this?
Yes, you can display members selected by group and sex with the admin member search tool so it can be done. Just need to add code to count totals.
Yes, I figured that would be the case, but I want this displayed as a box on my index, not within the member search tool. Unfortunately, I am not very versatile in code and am unsure on how to code such a thing w/o knowing where to start.
It's not simple, you'd have to run a query on members table to sort members by id_group and gender.
Hypothetically couldn't you take the gender count of the entire website from the stats page, then take the membercount of each group to potentially find the answer? Once again, I'm not well versed in PHP/JavaScript. Any help would be appreciated.
maybe something like this:(for smf2.0.*)
create this function in Load.php
function usergroupgender()
{
global $smcFunc, $context;
$result = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.gender, mem.id_group, mg.group_name
FROM {db_prefix}members as mem
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)
WHERE gender > {int:gender_var}
',
array(
'gender_var' => 0,
)
);
while ($row = $smcFunc['db_fetch_assoc']($result))
{
//male
if ($row['gender'] == 1) {
$context['usergroupgender'][$row['group_name']]['count_m'][] = $row['id_member'];
$context['usergroupgender'][$row['group_name']]['Male'] = count($context['usergroupgender'][$row['group_name']]['count_m']);
}
//female
if ($row['gender'] == 2) {
$context['usergroupgender'][$row['group_name']]['count_f'][] = $row['id_member'];
$context['usergroupgender'][$row['group_name']]['Female'] = count($context['usergroupgender'][$row['group_name']]['count_f']);
}
}
$smcFunc['db_free_result']($result);
}
then you can call the function in any template and use the variables with the global var $context['usergroupgender']
usergroupgender();
echo'<pre>';
print_r($context['usergroupgender']);
echo'</pre>';
[Administrator] => Array
(
[count_m] => Array
(
[0] => 1
)
[Male] => 1
)
The stats page seems to calculate that on the fly, so its data cannot be used here.