MyBB Hacks

Full Version: Counting in array (php)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello again,

I added this to my index.php file for mybb:

Code:
$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");

// Not set
$stats_cache = $cache->read("stats");
$num_notset = $stats_cache['numusers'] - $num_aldmeri - $num_daggerfall


My problem is, how would i change this code to use an array instead? something such as counting Male, Female, Not Set all together, but at the same time i can still use the above to count them individually too.

(i know the numusers will count all of them together, but this is for a different purpose other than Gender field).

IMO it be better to store the result into the cache and update it every now and then (maybe every 10 minutes).
yes, that would probably be better to do, but i am unsure how to do so to be honest.

SQL Code
SELECT fid3, COUNT(*) AS count
FROM mybb_userfields
GROUP BY fid3

Thank you guys for the replies.

how would i go about adding this code to the cache and purging/resyncing it every time someone is to update the profile field. or if that is too difficult, maybe just every 10 minutes as suggested

edit: setting it up in Task manager looks easy enough. its mostly the php that seems hard - such as where to put the code from my first post and adding the additional stuff needed to make it work in the task manager.
Caching is tricky, yes.  I'd just query every time for simplicity's sake (and stick an index on the fid3 column).
Reference URL's