xwishmasterx Posted April 26, 2011 Share Posted April 26, 2011 I have a simple code that should count my online members for a team: $online_members = mysql_query ("SELECT count(vtp_tracking.credit_members_id) as members FROM vtp_tracking WHERE action_date>date_sub(NOW(),interval 10 minute) AND teamid=".$rsget_team_id['team_id']." GROUP BY credit_members_id") or die(mysql_error()); $rs_online_members = mysql_fetch_array( $online_members ); my problem is getting the actual count, as I get the wrong amount of online members. Basicaly I count the unique member id where the team id is the same as the user (teamid=".$rsget_team_id['team_id']." ). What should I group by to count the numbers of different "vtp_tracking.credit_members_id" ? Link to comment https://forums.phpfreaks.com/topic/234775-need-help-with-correct-group-by-might-be-something-else/ Share on other sites More sharing options...
shlumph Posted April 26, 2011 Share Posted April 26, 2011 From what I gather, you are probably wanting to group by the teamid. But, since you're already filtering out all the other teams except the one you want, you don't need the GROUP BY clause. That is what you want, right? The number of online members from a certain team? Link to comment https://forums.phpfreaks.com/topic/234775-need-help-with-correct-group-by-might-be-something-else/#findComment-1206584 Share on other sites More sharing options...
xwishmasterx Posted April 26, 2011 Author Share Posted April 26, 2011 I believe you're right. Then my problem is somewhere else. As of now it is counting number of results; so if a member is listed 4 times it counts as 4, not 1.. Link to comment https://forums.phpfreaks.com/topic/234775-need-help-with-correct-group-by-might-be-something-else/#findComment-1206654 Share on other sites More sharing options...
shlumph Posted April 27, 2011 Share Posted April 27, 2011 You'd probably want COUNT(DISTINCT credit_members_id), then. But it's hard to tell without your DB layout for the tables, some example data, and the expected results. Link to comment https://forums.phpfreaks.com/topic/234775-need-help-with-correct-group-by-might-be-something-else/#findComment-1206678 Share on other sites More sharing options...
Muddy_Funster Posted April 27, 2011 Share Posted April 27, 2011 Why would the same member be listed 4 times if you are grouping by member? Link to comment https://forums.phpfreaks.com/topic/234775-need-help-with-correct-group-by-might-be-something-else/#findComment-1206788 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.