I have a database full of users scores for a game I created. I’m trying to add a feature to show the user what their current rank is.
I need a query that will sort the rows by score DESC and then locate the users score and get his / her rank by their username.
I know it’s a pretty simple query, but my mind just isn’t working right now.
CREATE TABLE HighScores(
id int(11) NOT NULL auto_increment
,deviceID varchar(100) NOT NULL
,username varchar(50) NOT NULL
,score varchar(10) NOT NULL
,game int(2) NOT NULL
,spins int(10) NOT NULL
,PRIMARY KEY (id)
);
Since i don’t know your table structure it’s hard to come up with a query.
This article does exactly what you want.
Example query:
The magic is in the variable rownum, which is a variable incremented for each row.