Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.