Jump to content

Rank position (with ties)


verdeandrea
 Share

Recommended Posts

Hello guys,

this is my situation.

I have a website where users can do some tests. At the end of the test they earn some points.

Se there is a rank showing users results.

I'm trying to understand what could be the best way to store and organize data in this case.

I'm thinking about using ProField Table to create an edit the rank. 

Every row of the table would have this information: Rank position - User - Points

Everytime a user do a new test the rank should be updated.

Can this be a good solution?

Can i find and edit row of the table via API?

Can Table field be sorted by one column?

I was also thinking about using repeater. One repeater item for every rank row.

Another problem is the rank should be like this:

-  1.  John Smith  -  240

-  2.  John Doe  -  200

-  2.  Jane Doe  -  200

-  3.  Bla bla bla - 180

etc.

So if more user have the same points they should have the same rank position.

I need to show "You rank position is: n" in home page for every user.

So i would like to have a function like "get_rank_position($user)" but i have no idea where to start with this.

Have any of you ever done something like that?

Thanks!

Link to comment
Share on other sites

It wasn't so hard in the end.

I decided not to store the rank in the database, but just constructing it from the user points.

I solved the problem of users with the same rank position in this way

// I get the players pages and sort them by points
$players = $users->find("sort=-user_points, sort=name");

// I explode the players into a scores array
$scores = $players->explode("user_points");

// Using array_unique to remove duplicated scores
$unique_scores = array_unique($scores);

// With array_unique previous key are preserved so i need to create a new array with new keys
$reindexed_scores = array_values($unique_scores);

// I cycle through players
foreach($players as $player) { 
        // I get the key of the user pointe in the array
        $position = array_search($player->user_points, $reindexed_scores);
        echo $position;
        echo " - ";
        echo $player;
        echo " - ";
        echo $player->user_points;
}
Hope this could help someone else with the same need.
                   

 
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...