Counting in array (php)
Gstone Offline
Member
***
Posts: 55
Joined: May 2012
Post: #1
Counting in array (php)
hello again,

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

Code:
1
2
3
4
5
6
$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).

(This post was last modified: 09-13-2012 02:08 PM by Gstone.)
09-13-2012 02:07 PM
Find all posts by this user Quote this message in a reply
Sama34 Offline
Senior Member
****
Posts: 490
Joined: May 2011
Post: #2
RE: Counting in array (php)
IMO it be better to store the result into the cache and update it every now and then (maybe every 10 minutes).

Support PM's will be ignored. Yipi
Plugins: Announcement Bars - Custom Reputation - Mark PM As Unread
(This post was last modified: 09-13-2012 03:06 PM by Sama34.)
09-13-2012 03:05 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Gstone Offline
Member
***
Posts: 55
Joined: May 2012
Post: #3
RE: Counting in array (php)
yes, that would probably be better to do, but i am unsure how to do so to be honest.
09-13-2012 03:07 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: Counting in array (php)

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


My Blog
09-13-2012 07:07 PM
Find all posts by this user Quote this message in a reply
Gstone Offline
Member
***
Posts: 55
Joined: May 2012
Post: #5
RE: Counting in array (php)
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.
(This post was last modified: 09-14-2012 06:54 PM by Gstone.)
09-14-2012 06:44 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #6
RE: Counting in array (php)
Caching is tricky, yes.  I'd just query every time for simplicity's sake (and stick an index on the fid3 column).

My Blog
09-14-2012 09:58 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: