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 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) 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 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? 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 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. 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.. 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 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 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! Link to comment https://forums.phpfreaks.com/topic/211245-count-grouped-results/#findComment-1101535 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.