Skip to main content
Inspiring
July 11, 2012
Answered

Need to add a number to results from recordset

As you can probably tell, I am not sure of what I am asking here, and as a result I can't find it on google.

How do I add a number to results returned from a recordset? I am goiing to need to display a highest score first descending to the lowest last, but I need to display where each score is positioned... like so:

1. John scored 6769

2. Bill scored 5698

3. Annie scored 5046

4. Frank scored 4908

5. Mary scored 4725

6. Tom scored 3375

7. and so on...

It'll be for PHP and MySQL.

Thanks.

Mat

This topic is closed to new replies. Start a new post to keep the conversation going.
matthew stuartCorrect answer
Inspiring
July 11, 2012

I found what I was looking for...

It's MySQL's 'rank' function.

Here's the code if anybody needs it:

SELECT @curRank := @curRank + 1 AS rank, db_fld_colname, db_fld_score

FROM db_table, (SELECT @curRank := 0) r

ORDER BY db_fld_score DESC

1 reply

matthew stuartAuthorCorrect answer
Inspiring
July 11, 2012

I found what I was looking for...

It's MySQL's 'rank' function.

Here's the code if anybody needs it:

SELECT @curRank := @curRank + 1 AS rank, db_fld_colname, db_fld_score

FROM db_table, (SELECT @curRank := 0) r

ORDER BY db_fld_score DESC

Translate