Count Male/Female Specific Usergroup
Niki Offline
Junior Member
**
Posts: 29
Joined: Oct 2016
Post: #6
RE: Count Male/Female Specific Usergroup
(12-16-2017 10:13 PM)RateU Wrote:  If there are more than one conditions, you should use AND or OR, not ,

For example (based on your query):

PHP Code:
// Usergroup Number Counts
$num_male = $db->fetch_field($db->simple_select("userfields", "COUNT(ufid) as count", "usergroup IN ('4') AND fid3='Male'"), "count");
$num_female = $db->fetch_field($db->simple_select("userfields", "COUNT(ufid) as count", "usergroup IN ('4') AND fid3='Female'"), "count");


That unfortunately causes an error message.
“SQL Error:
1054 - Unknown column 'usergroup' in 'where clause'
Query:
SELECT COUNT(ufid) as count FROM mybbvo_userfields WHERE usergroup IN ('4') AND fid3='Male'”



(12-16-2017 09:13 AM)Niki Wrote:  

PHP Code:
$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 but it’s still wrong. Any tips? Smile

^ The above actually works but I think it is counting users in the group instead of males/females based on profile field. So I do believe I’m getting closer but this is the closest I get.

From reading MyBB docs, the simple select being used in the previous discussions seems to not be able to be used for grabbing usergroups and stuff? Or maybe I read the doc wrong. So I went with this instead.
(This post was last modified: 12-17-2017 04:16 AM by Niki.)
12-17-2017 03:08 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
RE: Count Male/Female Specific Usergroup - Niki - 12-17-2017 03:08 AM

 Standard Tools
Forum Jump: