MyBB Community Forums

Full Version: Count Userfield by Usergroup = Counting but not correctly.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
$num_male = $db->fetch_field( $db->query( "SELECT COUNT(*) as numberofmales FROM ".TABLE_PREFIX."users WHERE usergroup = 16 ", "fid5='Male'"), 'numberofmales' );
$num_female = $db->fetch_field( $db->query( "SELECT COUNT(*) as numberoffemales FROM ".TABLE_PREFIX."users WHERE usergroup = 16 ", "fid5='Female'"), 'numberoffemales' );

So I’ve gotten to here. It works but the number of males and females is the same when it should be 2 females and 0 males.
No error anymore (as my previous attempts threw many errors) but it’s still wrong. Any tips? It seems to be counting all users in the usergroup instead of the totals for those that have selected male or female.