Kingskin Posted November 6, 2005 Share Posted November 6, 2005 Hi, I'd like to be able to count the number of times the same data appears in a table. I know i could just use a standard COUNT to do it, but the trouble is I want to do it for every item in my table. An example. Say a column from my table called 'country' looks like this: country: Holland England Ireland England Italy Holand England I want to return a list of entries, numbered by the amount of times they occur, like this: England - 3 Holland - 2 Ireland - 1 Italy - 1 Can anyone help me with this please? Quote Link to comment https://forums.phpfreaks.com/topic/2810-count-number-of-times-data-appears/ Share on other sites More sharing options...
Kingskin Posted November 6, 2005 Author Share Posted November 6, 2005 Never mind, sorted now. For anyone else who may turn ths thread up after a search, here's what I did: $query = "SELECT location FROM episode"; $result = mysql_query($query); while ( $row = mysql_fetch_array($result)) { extract($row); $locations[] = $location; } $output = array_count_values($locations); Quote Link to comment https://forums.phpfreaks.com/topic/2810-count-number-of-times-data-appears/#findComment-9415 Share on other sites More sharing options...
ryanlwh Posted November 6, 2005 Share Posted November 6, 2005 FYI.. [!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] country, COUNT(country) FROM episode GROUP BY country [!--sql2--][/div][!--sql3--] Quote Link to comment https://forums.phpfreaks.com/topic/2810-count-number-of-times-data-appears/#findComment-9417 Share on other sites More sharing options...
Kingskin Posted November 7, 2005 Author Share Posted November 7, 2005 FYI.. [!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] country, COUNT(country) FROM episode GROUP BY country [!--sql2--][/div][!--sql3--] 315422[/snapback] Ah, Ok that looks like a better way of doing it, thanks Quote Link to comment https://forums.phpfreaks.com/topic/2810-count-number-of-times-data-appears/#findComment-9454 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.