MyBB Community Forums

Full Version: Custom field in Board statistics
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello,

Lets say I have for example the sex question. 3 choices, Male, Female and No comment. Can I somehow count what the users choose and show the results in the bottom were the The most users... are. Lets say there are 3 men, 1 woman and 6 No comments registered.

"There are 3 men, 1 woman and 6 No comments here on the forum" that should be the text displayed. Now, this is not the questions I want to use but this is just an example of it.

Is this possible?
This requires a modification of some sort.

In index.php, find:
eval("\$boardstats = \"".$templates->get("index_boardstats")."\";");
Before that line, add:
$num_male = $db->fetch_field($db->simple_select("userfields", "COUNT(ufid) as count", "fid3='Male'"), "count");
$num_female = $db->fetch_field($db->simple_select("userfields", "COUNT(ufid) as count", "fid3='Female'"), "count");
// Other people
$stats_cache = $cache->read("stats");
$num_other = $stats_cache['numusers'] - $num_male - $num_female;

/* In the index_boardstats template, use the following variables:
    {$num_male}
    {$num_female}
    {$num_other}
*/
it didn't seem to work on my board: http://www.forums.totalityworks.co.cc
Did you do the bit in the orange comment area, i.e. add the variables to your index_boardstats template??
yeah. right under {$user_legend} and above {$reggedtoday}
Admin CP --> Configuration --> Profile Fields
The code above assumes the "ID" of the "Sex" field is 3. If it isn't you'll have to change fid3 in the code to fidX where X is the ID.

Also, the code assumes that the values of the "Sex" field is in English: Male, Female, Undisclosed, Other. If this has been changed you also need to change the code above to suit your language.
I've left all of that at default and my board is in English. I may have done something wrong, but I would have no idea what it could be.
I get the same error as you, just three 0. And they are over the stats board. I have choosen male as my sex but noone of them change. Do I have to change anything in the code?
The only bug I found in the code is that

$stats_cache['num_users']
should be
$stats_cache['numusers']
I changed that in the original code.

I tried it in my forum, and it works fine...

Link to your forums and a test account?
(2008-12-26, 09:50 PM)MCII-Totality Wrote: [ -> ]I've left all of that at default and my board is in English. I may have done something wrong, but I would have no idea what it could be.

Nobody marked their Sex as either Male or Female on your forum. I changed mine to Male, and I see 1 0 -1 (you just need to fix the bug in the above post). Otherwise, it is working on your forum.

You can just change the text in the template to something like

There are {$num_male} male users, ....
Pages: 1 2