budimir Posted January 27, 2008 Share Posted January 27, 2008 I have and ID field in a table and loads of information in it. I would like to count and display number of ID's in that column. So, basiclly, this is what I'd like to get: ID 54 = 13 times in table ID 16 = 55 times in table ID 78 = 100 times in table I hope you get what I mean. Please help Quote Link to comment https://forums.phpfreaks.com/topic/88041-solved-counting-the-biggest-number-of-entries-in-a-field/ Share on other sites More sharing options...
sasa Posted January 27, 2008 Share Posted January 27, 2008 SELECT COUNT(*) FROM table GROUP BY ID Quote Link to comment https://forums.phpfreaks.com/topic/88041-solved-counting-the-biggest-number-of-entries-in-a-field/#findComment-450417 Share on other sites More sharing options...
budimir Posted January 27, 2008 Author Share Posted January 27, 2008 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/88041-solved-counting-the-biggest-number-of-entries-in-a-field/#findComment-450421 Share on other sites More sharing options...
budimir Posted January 27, 2008 Author Share Posted January 27, 2008 SELECT COUNT(*) FROM table GROUP BY ID That's a part of it!! How do I display which is which???? Quote Link to comment https://forums.phpfreaks.com/topic/88041-solved-counting-the-biggest-number-of-entries-in-a-field/#findComment-450453 Share on other sites More sharing options...
marcus Posted January 27, 2008 Share Posted January 27, 2008 $sql = "SELECT COUNT(*) as highest FROM table GROUP BY ID"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ echo "ID " . $row['id'] . " has " . $row['highest'] . " occurrences<br>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/88041-solved-counting-the-biggest-number-of-entries-in-a-field/#findComment-450454 Share on other sites More sharing options...
budimir Posted January 27, 2008 Author Share Posted January 27, 2008 $sql = "SELECT COUNT(*) as highest FROM table GROUP BY ID"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ echo "ID " . $row['id'] . " has " . $row['highest'] . " occurrences<br>\n"; } For some reason I'm not getting the ID. This is the result "ID has 5 occurrences". Is there any reason why it's not working? Quote Link to comment https://forums.phpfreaks.com/topic/88041-solved-counting-the-biggest-number-of-entries-in-a-field/#findComment-450458 Share on other sites More sharing options...
laffin Posted January 27, 2008 Share Posted January 27, 2008 $sql = "SELECT ID,COUNT(*) as highest FROM table GROUP BY ID"; Quote Link to comment https://forums.phpfreaks.com/topic/88041-solved-counting-the-biggest-number-of-entries-in-a-field/#findComment-450478 Share on other sites More sharing options...
budimir Posted January 27, 2008 Author Share Posted January 27, 2008 Thanks for this! I just need one more thing. How do I display an ID with the biggest number in field "highest"? Quote Link to comment https://forums.phpfreaks.com/topic/88041-solved-counting-the-biggest-number-of-entries-in-a-field/#findComment-450483 Share on other sites More sharing options...
Bauer418 Posted January 27, 2008 Share Posted January 27, 2008 SELECT ID,COUNT(*) as highest FROM table GROUP BY ID ORDER BY highest DESC Quote Link to comment https://forums.phpfreaks.com/topic/88041-solved-counting-the-biggest-number-of-entries-in-a-field/#findComment-450486 Share on other sites More sharing options...
budimir Posted January 27, 2008 Author Share Posted January 27, 2008 SELECT ID,COUNT(*) as highest FROM table GROUP BY ID ORDER BY highest DESC Thanks for this. But I need ONLY an ID with the "highest" number. Quote Link to comment https://forums.phpfreaks.com/topic/88041-solved-counting-the-biggest-number-of-entries-in-a-field/#findComment-450493 Share on other sites More sharing options...
budimir Posted January 27, 2008 Author Share Posted January 27, 2008 This would be the solution to my problems. SELECT ID,COUNT(*) as highest FROM obilasci GROUP BY ID ORDER BY highest DESC limit 1 Thanks for you effort, guys!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/88041-solved-counting-the-biggest-number-of-entries-in-a-field/#findComment-450511 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.