Jump to content

Find the rank of a user on my web site


sintax63

Recommended Posts

I've got a web site I'm working on and it is user driven. Users can submit content into a directory, which is how the site grows. One thing I want to implement is a "ranking system" which says "User X" has contributed the most and is in 1st place, "User Y" is in second... and so forth. I'd also like to assign a points system, which I have working by using the following:

 

$u_count	= mysql_result(mysql_query("SELECT COUNT(*) FROM directory WHERE user='$u_id' AND status='1'"),0);
$u_points	= $u_count * 10;

 

The other part I'm at a loss with. I know I need to use that query above to get the total number of submissions for each user, but am unsure how to then compare them to each other and pull out the top five, for example.

 

Any thoughts?

 

Link to comment
Share on other sites

Works great! I was actually just doing that when you were replying as I figured it would make a difference.

 

If I could pick your brain one more time if you have a minute. For the points I'm just take their entry count and multiplying by 10 but I would like to get a bit more detailed if at all possible. The data I'm collecting are for locations so I'm obviously collecting address, phone number, etc as well as a photo if available.

 

Is there a way that I can say that every entry = 10 points, but if a photo is added then it = 20 (or a phone number is an extra 5 for example)? Right now I'm just using that original code above.

Link to comment
Share on other sites

Actually I just found a bug with the code. The #1 spot is going to the user with "1" as their ID (that's me). #2 should be the user with an ID of "9" - however it skips him and goes to someone with an ID of "104" (who only has one entry).

 

:shrug:

 

Link to comment
Share on other sites

I've been trying to debug this all afternoon. So far my top 5 looks like this (the number being that of submissions):

 

35

1

74

2

19

 

The guy with 74 submissions should be #1 (his user id is "9") but me (with user id "1") is at the top with 35 submissions.

 

Does anyone have any idea on how I can fix this code so it pulls and displays correct?

 

Much thanks!

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.