QuePID Posted July 22, 2010 Share Posted July 22, 2010 Hi, I have the following query to detect dupes: SELECT tablename.*, COUNT(*) FROM tablename GROUP BY fieldname HAVING COUNT(*) > 1 and I would like to display COUNT(*) via echo in the results output, how do I accomplish this? I've tried echo "$row[COUNT(*)]"; with no success. I am basically wanting to display the number of times each field is duplicated. I notice if I use phpmyadmin and run the query it displays a COUNT(*) field that details the repetitions and would like to do the same via my php. Link to comment https://forums.phpfreaks.com/topic/208557-display-count/ Share on other sites More sharing options...
premiso Posted July 22, 2010 Share Posted July 22, 2010 COUNT(*) is generally not a good idea. It is better to put the id field name in there. This will make the query more efficient. To be able to pull the data you want to alias the column: SELECT tablename.val1, tablename.val2, COUNT(id) as id_cnt FROM ... Then you would reference it by $results['id_cnt'] Link to comment https://forums.phpfreaks.com/topic/208557-display-count/#findComment-1089661 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.