Jump to content

Help with a query plz


2oMst

Recommended Posts

Ok i tried helping out a guy about a ranking system he tried to do on his site and couldn\'t quite get the query working.

 

What I want:

I have a forum_1_msg table with a user column.

I would like to have a ranking system of the most posts.

A post = 1 row in that table.

 

In theory:

Display every user once, using DISTINCT and count how many times this user has posted on the forum, and then sort it.

 

A few queries I tried:

 


mysql_query("SELECT DISTINCT user, count(user) AS nbr_posts FROM forum_1_msg ORDER BY nbr_posts DESC");



mysql_query("SELECT GROUP_CONCAT(DISTINCT user) AS cur_user, GROUP_CONCAT(count(cur_user)) AS nbr_posts FROM forum_1_msg ORDER BY nbr_posts DESC");

 

I tried many other queries, the number 1 I thought would be the most accurate. After reading the doc on mysql.com I thought the number 2 query would be more appropriate but hey .... Both don\'t work.

 

Any help here ???

 

PS: I know this is not the best way for this to work but it\'s mainly for educational purpose on mysql_querying

 

Thank you

Link to comment
Share on other sites

ahh !! yes, very nice

 

GROUP BY power :)

 

I\'ll experiment with group by, thank you.

 

ps: anyone know of any good sites showing all the syntax you can put into a mysql_query ... ?? (besides mysql.com)

Link to comment
Share on other sites

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.