newb Posted August 20, 2010 Share Posted August 20, 2010 in my mysql query, after the results have been grouped is there any way to count the results? i have a end result like this: 784 | x.x.x.x 754 | x.x.x.x 784 | x.x.x.x so how can i count the first column after its been grouped by IPs? here is my query: SELECT * FROM `hits`GROUP BY ip Quote Link to comment https://forums.phpfreaks.com/topic/211245-count-grouped-results/ Share on other sites More sharing options...
tomtimms Posted August 20, 2010 Share Posted August 20, 2010 If you are looking to count your results, then you would use $count = mysql_num_rows($result) Quote Link to comment https://forums.phpfreaks.com/topic/211245-count-grouped-results/#findComment-1101494 Share on other sites More sharing options...
newb Posted August 20, 2010 Author Share Posted August 20, 2010 i know that but thats not what im trying to do. i need to count the number of occurences for the first column. for example, im trying to get output like this..: 784: 2 occurences 754: 1 occurence Quote Link to comment https://forums.phpfreaks.com/topic/211245-count-grouped-results/#findComment-1101499 Share on other sites More sharing options...
tomtimms Posted August 20, 2010 Share Posted August 20, 2010 Well you can always use the count function if your looking to get just the first column. Are you trying to count how many times a certain result is returned or is it just every result you want counted to see how many times it was found? Quote Link to comment https://forums.phpfreaks.com/topic/211245-count-grouped-results/#findComment-1101505 Share on other sites More sharing options...
Fadion Posted August 20, 2010 Share Posted August 20, 2010 As suggested, use COUNT: SELECT COUNT(*) AS nr FROM hits GROUP BY ip Quote Link to comment https://forums.phpfreaks.com/topic/211245-count-grouped-results/#findComment-1101506 Share on other sites More sharing options...
newb Posted August 20, 2010 Author Share Posted August 20, 2010 yeah that doesnt work because it counts the results before it was grouped by IP, so the occurences are way off..i need to count the results after its been grouped by IP. Quote Link to comment https://forums.phpfreaks.com/topic/211245-count-grouped-results/#findComment-1101512 Share on other sites More sharing options...
newb Posted August 20, 2010 Author Share Posted August 20, 2010 so.. Quote Link to comment https://forums.phpfreaks.com/topic/211245-count-grouped-results/#findComment-1101517 Share on other sites More sharing options...
newb Posted August 20, 2010 Author Share Posted August 20, 2010 bump Quote Link to comment https://forums.phpfreaks.com/topic/211245-count-grouped-results/#findComment-1101527 Share on other sites More sharing options...
sasa Posted August 20, 2010 Share Posted August 20, 2010 SELECT *, COOUNT(*) AS num FROM (SELECT * FROM `hits`GROUP BY ip) a GROUP BY cullumn_name_with_numbers_784_and_so_on Quote Link to comment https://forums.phpfreaks.com/topic/211245-count-grouped-results/#findComment-1101534 Share on other sites More sharing options...
newb Posted August 20, 2010 Author Share Posted August 20, 2010 SELECT *, COOUNT(*) AS num FROM (SELECT * FROM `hits`GROUP BY ip) a GROUP BY cullumn_name_with_numbers_784_and_so_on ah...works like a charm, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/211245-count-grouped-results/#findComment-1101535 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.