Jump to content

[SOLVED] HELP: (PHP/SQL) Echo top entries from DB


spasme

Recommended Posts

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  ;D

Thanks in advance!

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.