MillerMedia
MillerMedia

Reputation: 3671

Get Rank User with PHP/MySQL Without Inserting Current User's Score into the table

I have a web-based game I'm creating in PHP with a MySQLi database. I'm looking to get the 'rank' of a user but it's a little different than other answers I've seen on here.

The user finishes the game and their score, time and rank will show on the final page. Then, they can choose to signup and save their score AFTER the game. So I need to be able to get the rank of the user compared to where it would fit into the already populated table without actually inserting it into the table.

My 'score' table is set up with rows

Essentially, if a user has an identical score to another user, it then checks the time variable and ranks it with that secondary option.

Upvotes: 1

Views: 276

Answers (1)

James
James

Reputation: 22237

You could incorporate the new score into a query something like

SELECT id, username, score, time FROM scores
UNION ALL
SELECT 0 as id, 'YOURSCORE' as username, 99999 as score, 45 as time
ORDER BY score desc, time desc

Upvotes: 2

Related Questions