I’m making a PHP battle system, and need to sort out the ranking.
How I want it to work is say there’s 100 players, and you’re rank 90. You can challenge players 5 ranks above, so say you challenge and beat the player in rank 85, then YOU become 85 and he becomes 86.
I’m not sure how to do this with a database though. How to set it out, or store rank. Obviously I can’t save a field with your ‘rank’ since if you win it’d have to edit every single players rank below you in the database, wouldn’t it?
Any ideas would be helpful.
I recommend you do keep a rank field and relax the bottleneck in the queries:
In your example use something like
This will change ranks
which looks like what you want, but uses a single query, that can leverage an index and touches only 6 rows.
Edit
To facilitate maintenance (fix rank numbers, if there are holes etc.), run
once, then use
to close gaps in the table. Mind that this touches all rows!