Skip to content
Advertisement

Basic ranking of MySQL data and printing result with php

I have a table which in which I want to rank rows where one of the columns equals a value I have defined.

For example in this table I want to get all rows where Col1 = a, then find what is the rank of the row in which Col3 = Ross (ranked by score in Col2).

JavaScript

Ultimately I want to calculate this:

JavaScript

And print the result “2”.

I can sort the table with this query, but dont; know how to then print the result I need (with php).

JavaScript

Advertisement

Answer

Try this:

JavaScript

Here is a test run that shows it working.

If you want to find Ross’s rank you can run the query with WHERE Col3 = 'Ross' added and only the rank column selected, as demonstrated here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement