0

I try to write a litte Highscore list. In Fact, the list work well, but i don´t want to display all entries. Thats why I try to let users who are to worse to be displayed, know how worse they are.

I use this:

$holrang = mysql_query("SELECT @ROW := @ROW + 1 AS row, scoreScore FROM score, (SELECT 
@ROW := 0) r WHERE scoreScore = '$score' ") or die(mysql_error()); 
$getrang = mysql_fetch_assoc($holrang);
$rang = $getrang['row'];

//$score is the score that the User reached and submit to the list. 

to get the "rang" of the User. But the query only replay "1".

Another try to explain:

We have a Scorelist:

  • Player1 10
  • Player2 20
  • Player3 30
  • Player4 40
  • Player6 60

and only display the first 3. Now Player5 submit his score of 50 to the list. He is in fact on rang 5. I want a query to get this "5".

Can you give me a hint?

Kristjan
  • 13
  • 3
  • [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](http://j.mp/XqV7Lp). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. – Kermit Jun 04 '14 at 13:14
  • Leaving aside which PHP driver you should use... I still don't get what's this query intended to do. Is it supposed to find all users whose score equals ```$score``` ? – ffflabs Jun 04 '14 at 13:17
  • See http://stackoverflow.com/questions/3126972/with-mysql-how-can-i-generate-a-column-containing-the-record-index-in-a-table – hlscalon Jun 04 '14 at 13:23
  • $score is the Score the User have reach. For Example, the User have the Score "10". Another User have the Score "15". And thats all in the list. Than should the query replay a "2". Because the Score of the User with 10 Points is not as high as the Score of the user with 15 Points. I use php in version 5.3.28, and mySql in version 5.5.35 – Kristjan Jun 04 '14 at 13:28
  • can you show me the table columns? – Janaka R Rajapaksha Jun 04 '14 at 14:28
  • Of course: 1 scoreID int(11) 2 scoreName varchar(15) 3 scoreDate timestamp 4 scoreScore int(10) – Kristjan Jun 04 '14 at 14:46

0 Answers0