I have a list of the top ten users sorted by points. The problem is that when two users have the same number of points, everything gets messed up. So if user A and user B had the same amount of user points the ranking order gets messed up... So if it has user A ranked 5th and user B was ranked 4th, it will show user B above user A... so the numbers would go like, 1, 2, 3, 5, 4, 6, 7, 8, 9, 10. Where 4 and 5 are switched around...

Comments

mpaler’s picture

I agree that the way rank is doled out is a little counterintuitive. I have alot of users who have the same number of user points, yet their ranks are all different. Personally, I think all people with the same # of points should have the same rank.

Here's my way of handling that...

Around line 265 in userpoints_top_contributors.module

         // Populate the rank field
	$result = db_query("SELECT *
  	FROM {userpoints_top_contributors}
  	ORDER BY lifetime_points DESC");

		$rank = 1;
		while ($data = db_fetch_object($result)) {
			if (!isset($current_points)){
				static $current_points;
				$current_points = $data->lifetime_points;
			}
			if($data->lifetime_points < $current_points){
				$current_points = $data->lifetime_points;
				$rank++;
			}
			
  		db_query("UPDATE {userpoints_top_contributors}
    		SET rank = %d
    		WHERE uid = %d", $rank, $data->uid
  		);
		}
walker2238’s picture

Hey good idea. I actually made a block with something like that but only returning the first 10 results. It never crossed my mind to just apply it to everything. I'll give it a try.

kmillecam’s picture

Assigned: Unassigned » kmillecam
Status: Active » Fixed

Committed to dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.