# MYSQL / PHP Scoreboard - Return position

**URL:** https://forum.kirupa.com/t/mysql-php-scoreboard-return-position/302905
**Category:** programming
**Created:** [January 9, 2010, 6:14pm UTC](https://forum.kirupa.com/t/mysql-php-scoreboard-return-position/302905 "2010-01-09T18:14:50Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Mental](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@Mental](https://forum.kirupa.com/u/Mental)
#### Post date: [January 9, 2010, 6:14pm UTC](https://forum.kirupa.com/t/mysql-php-scoreboard-return-position/302905/1 "2010-01-09T18:14:50Z")

</div>

Hi,

Basically I’ve got a MYSQL database that has tables that relate to levels on my game for the following to be stored in:

id, usernames, scores and times.

I’ve worked out how to add new entries into the database and load a set sample after ordering the table (e.g. the highest 10 scores) but is it possible to:

add the score, sort by score then return the position of that score and the next 10 scores below it?

I searched on google and managed to find an example that someone had solved, but didn’t understand it really and when I tried to implement it, it wouldn’t work.

```auto
SET @rownum := 0;

$result = SELECT * FROM(SELECT @rownum := @rownum+1 AS rank, id, name, score, time, ms FROM $table ORDER BY score DESC) AS derived_table WHERE rank = 3;

```

I’ve only done a very minimal amount of both PHP and MySQL so it is likely that I have overlooked something here, but I couldn’t really find any other examples and spent a while trying to get that code to work.

Any input is appreciated,  
Mental.
