unemployment Posted February 15, 2011 Share Posted February 15, 2011 How do I total unique id's with php or MySQL. For instance in MySQL I have... ID 1 1 3 4 2 1 1 3 How can I total all of the 1's, all of the twos, all of the threes and so forth. I have four 1's, one 2, two 3's and so forth... Link to comment https://forums.phpfreaks.com/topic/227745-total-unique-ids-with-php-and-mysql/ Share on other sites More sharing options...
waterssaz Posted February 15, 2011 Share Posted February 15, 2011 You mean you want to count how many occurences of each there are? If so just do a simple GROUP BY query For example Select ID, COUNT(ID) from [YOUR_TABLE_NAME] GROUP BY ID or in PHP you can use the function array_count_values(array) Hope either of these helps :-) Regards Sarah Link to comment https://forums.phpfreaks.com/topic/227745-total-unique-ids-with-php-and-mysql/#findComment-1174533 Share on other sites More sharing options...
Maq Posted February 15, 2011 Share Posted February 15, 2011 It's more efficient to do this calculation in SQL than PHP. Link to comment https://forums.phpfreaks.com/topic/227745-total-unique-ids-with-php-and-mysql/#findComment-1174574 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.