sintax63 Posted July 13, 2011 Share Posted July 13, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/241899-find-the-rank-of-a-user-on-my-web-site/ Share on other sites More sharing options...
gristoi Posted July 13, 2011 Share Posted July 13, 2011 $u_count = mysql_result(mysql_query("SELECT COUNT(*) AS 'Total Entries', user FROM directory WHERE user='$u_id' AND status='1' GROUP BY user ORDER BY 'Total Entries' DESC LIMIT 5"),0); Quote Link to comment https://forums.phpfreaks.com/topic/241899-find-the-rank-of-a-user-on-my-web-site/#findComment-1242251 Share on other sites More sharing options...
sintax63 Posted July 13, 2011 Author Share Posted July 13, 2011 Thanks for the help, gristoi. The above line of code code is just returning the count for one user, the top one. Does this need to go into a loop instead of just echoing out the u_count variable? Quote Link to comment https://forums.phpfreaks.com/topic/241899-find-the-rank-of-a-user-on-my-web-site/#findComment-1242261 Share on other sites More sharing options...
gristoi Posted July 13, 2011 Share Posted July 13, 2011 sorry, remove the 'where user=' part out of the query Quote Link to comment https://forums.phpfreaks.com/topic/241899-find-the-rank-of-a-user-on-my-web-site/#findComment-1242265 Share on other sites More sharing options...
sintax63 Posted July 13, 2011 Author Share Posted July 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/241899-find-the-rank-of-a-user-on-my-web-site/#findComment-1242270 Share on other sites More sharing options...
sintax63 Posted July 13, 2011 Author Share Posted July 13, 2011 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). Quote Link to comment https://forums.phpfreaks.com/topic/241899-find-the-rank-of-a-user-on-my-web-site/#findComment-1242285 Share on other sites More sharing options...
sintax63 Posted July 13, 2011 Author Share Posted July 13, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/241899-find-the-rank-of-a-user-on-my-web-site/#findComment-1242444 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.