viion Posted April 8, 2009 Share Posted April 8, 2009 I want to be able to count the amount of values that is grouped. For example User A has Item1 User A has Item1 User A Has Item1 after grouped it'd be like User A has Item1 (x3) the x3 is a value I need, wasn't sure to post this in php or sql, I know the Group by will effect counts and I'm not really counting how many times a Name Appears because User A might have Item2 or 3 or 10, I just need to count the number of times User A has the same Item multiple times. Anyone know how to do this? Greatly appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/153111-count-the-amount-in-a-group/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 8, 2009 Share Posted April 8, 2009 If you are querying for just one user, GROUP BY item would give you a count of the number if each different items for that one user. If you are querying for more than one user and you want a count per user, per item, use GROUP BY user, item Quote Link to comment https://forums.phpfreaks.com/topic/153111-count-the-amount-in-a-group/#findComment-804258 Share on other sites More sharing options...
viion Posted April 8, 2009 Author Share Posted April 8, 2009 How do I get the variable of the group to output the number? Atm I do something like: (this is by item, not user, but same principles) $itemtrack = mysql_query("SELECT * FROM ". ITEMTRACK_DATABASE ." GROUP BY ". ITEMTRACK_DATABASE_ITEM ." ORDER BY ". ITEMTRACK_DATABASE_ITEM .""); this is then in a while mysql_fetch_array which will output the usual stuff. How do I make a php variable like $amount = the total in a group specific to a user. (they'll be more than 1 user) Quote Link to comment https://forums.phpfreaks.com/topic/153111-count-the-amount-in-a-group/#findComment-804261 Share on other sites More sharing options...
PFMaBiSmAd Posted April 8, 2009 Share Posted April 8, 2009 It would probably help if you read this - http://dev.mysql.com/doc/refman/5.0/en/counting-rows.html Quote Link to comment https://forums.phpfreaks.com/topic/153111-count-the-amount-in-a-group/#findComment-804264 Share on other sites More sharing options...
fenway Posted April 14, 2009 Share Posted April 14, 2009 I don't actually see a mysql COUNT() function anywhere, either. Quote Link to comment https://forums.phpfreaks.com/topic/153111-count-the-amount-in-a-group/#findComment-809669 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.