spasme Posted August 12, 2008 Share Posted August 12, 2008 Hey guys, I'm sure this is a simple thing to do but i just can't figure it out right now ??? My DB looks something like this: ---ID--------- ---Title--------- ---POST--------- ---OWNER--------- 1 Lipsum Title01 Lipsum Post01 Owner01 2 Lipsum Title02 Lipsum Post02 Owner02 3 Lipsum Title03 Lipsum Post03 Owner03 4 Lipsum Title04 Lipsum Post04 Owner01 The thing i need to do is echo the top 10 owners from this table. To be more precise, i need to count the number of entries for each 'owner' and display the top 10 owners that have the most entries associated to their account. So it should look something like this: #1. Owner01 - 2 posts #2. Owner02 - 1 posts ---------------------- #x. UserXXX - X posts I'd really apreciate some help on this Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/119304-solved-help-phpsql-echo-top-entries-from-db/ Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 Owner should be an INT to represent their user id rather than than username, but whatever. Try: SELECT COUNT(*) AS total, owner FROM yourtable GROUP BY owner ORDER BY total LIMIT 10; And use the proper table name and proper capitalization on owner. Not sure if it was meant to be in caps like in your post. Quote Link to comment https://forums.phpfreaks.com/topic/119304-solved-help-phpsql-echo-top-entries-from-db/#findComment-614551 Share on other sites More sharing options...
craygo Posted August 12, 2008 Share Posted August 12, 2008 $sql = "SELECT COUNT(`OWNER`) AS `o_count`, `OWNER`, `Title`, `POST` FROM `tablename` GROUP BY `OWNER` ORDER BY `o_count` DESC LIMIT 10"; Think that should do it, not tested though Ray Quote Link to comment https://forums.phpfreaks.com/topic/119304-solved-help-phpsql-echo-top-entries-from-db/#findComment-614557 Share on other sites More sharing options...
spasme Posted August 12, 2008 Author Share Posted August 12, 2008 HOLLY COW, you guys are fast!! it works fine! so simple *doh* :-X Thanks for the help! Happy Coding! [sOLVED] Quote Link to comment https://forums.phpfreaks.com/topic/119304-solved-help-phpsql-echo-top-entries-from-db/#findComment-614566 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.