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 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 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! 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???? 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"; } 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? 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"; 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"? 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 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. 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!!!!! 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
Archived
This topic is now archived and is closed to further replies.