XP Leveling System - PHP

Posted by Michael Rich on Stack Overflow See other posts from Stack Overflow or by Michael Rich
Published on 2012-09-18T20:53:55Z Indexed on 2012/09/18 21:38 UTC
Read the original article Hit count: 221

Filed under:
|

Rank Table

  • ID, Primary Key
  • RANK, The rank or level, 1 being the highest and 3 the lowest
  • MIN_SCORE, The minimum amount of point or XP needed to reach the rank
  • NAME, The associated name of the rank

    Rank Table
    +----+------+-----------+-------------------------+
    | ID | RANK | MIN_SCORE |          NAME           |
    +----+------+-----------+-------------------------+
    |  1 |    1 |     18932 | Editor-in-Chief         |
    |  2 |    2 |     15146 | Senior Technical Writer |
    |  3 |    3 |     12116 | Senior Copywriter       |
    +----+------+-----------+-------------------------+
    

Ranking Table

  • ID, Primary Key
  • FK_MEMEBER_ID, Foreign Key to member's Primary Key
  • FK_RANK, Foreign Key to Author Rank Table's Rank column (top)
  • SCORE, The member's current earned score or XP

    Ranking Table
    +-----+--------------+---------+-------+
    | ID  | FK_MEMBER_ID | FK_RANK | SCORE |
    +-----+--------------+---------+-------+
    |   1 |            1 |       1 | 17722 |
    |   2 |            2 |       2 | 16257 |
    |   3 |            3 |       3 | 12234 |
    +-----+--------------+---------+-------+
    

In my class I have stored the ranks -- matching those in the Rank Table -- and correlating minimum scores; RANK as key and MINIMUM_SCORE as value.

When a member's score (XP) is updated (up/down) I want to test that updated score against the below array to determine if their rank needs updating too.

private $scores = array('3' => '12116', '2' => '15146', '1' => '18932',);

Using the updated score, how could I determine the correlating rank from the above array?

Everything is open to scrutiny, this is my first time creating a ranking system so I hope to get it right :)

© Stack Overflow or respective owner

Related posts about php

Related posts about ranking