Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Need to add a number to results from recordset

Enthusiast ,
Jul 11, 2012 Jul 11, 2012

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

TOPICS
Server side applications
471
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jul 11, 2012 Jul 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
Enthusiast ,
Jul 11, 2012 Jul 11, 2012
LATEST

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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines