Skip to content
Advertisement

how do i count the amount of rows under a username?

I am making a forum and on the homepage I want to make some kind of a leaderboard where you can see the top 10 posters + and how much they have posted. I want to only get those users out of the database. Ill add a picture of my database. Please let me know.

Database

Advertisement

Answer

I don’t know what you mean, but if you mean the database query, it can be something like this:

SELECT username, 
       COUNT(*) AS total_post 
FROM your_table 
GROUP BY username 
ORDER BY COUNT(*) DESC 
LIMIT 10
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement