Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-21-2010, 06:30 AM   #1
LQ Newbie
Registered: Aug 2010
Posts: 4

Rep: Reputation: 0
how to implement user ranking in php with a huge number of users

Hi all

I'm writing a user ranking module for a site. This ranking depends on some criterias and it's possible to set or unset any one of these criterias in order to consider them in calculating the user rank or not. And here's the way I've implemented the ranking calculation :

when I set one or more of the criterias to be considered in ranking , for each user in the system I insert one record for each criteria , for example :

if I have 2 criterias and both are set and consider that I have two users , I'll have :

Ranking table
username | criteria | to_be_added | score
user1 | criteria1 | 1 | 0
user1 | criteria2 | 1 | 0
user2 | criteria1 | 1 | 0
user2 | criteria2 | 1 | 0

It means I just set the to_be_added field to 1 for all of them and leave the calculation of score for each criteria for each user to the time the user logins so that to prevent doing all these calculations at once , because there are a huge number of users ...

But there is one problem , if I want to show for example the best user (based on the highest score) , the result can't always be true because some users might not logged in at that time and their score might be zero .

How should I solve this problem ?

Thanks in advance for your help ...

Last edited by alenoosh; 08-21-2010 at 06:43 AM.
Old 08-22-2010, 09:00 PM   #2
Senior Member
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
You need to normalise your data.

Rule 1: Remove repeating groups of data.

user1 and user 2 are being repeated and so they should be removed from the table. Since the criteria1 and criteria2 scores are specific to the user they will go with the user. Hence you would get:

username criteria1 criteria2
user1            0         0
user2            0         0
Now if you want to display the criteria2 scores then the following will help:

SELECT username criteria2 from ranking ORDER BY criteria2 DESC
Without knowing the formula behind the criteria calculations it is difficult to say what would be the best way to calculate them. However, I would expect that the best way would be to do them as a batch job and then each time a user logs in to update it (if appropriate).


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LQ should come up with a smarter way of ranking users rob124 LQ Suggestions & Feedback 70 01-29-2010 11:34 PM
ditrowatch's ranking-bad gentoo users Brain Drop General 3 03-21-2003 08:21 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:34 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration