Jump to content

Ranking SQL results?


truCido

Recommended Posts

Basically I know how to create the query in SQL to output the result I want however I'm having problems outputting this onto a PHP page? Basically all I want to do is to put a rank along side each result.

[code]SELECT a1.planet, a1.score, COUNT( a2.score ) as rank
FROM pa_planet_listing a1, pa_planet_listing a2
WHERE a1.score <= a2.score
OR (
a1.score = a2.score
AND a1.planet = a2.planet
)
GROUP BY a1.planet, a1.score
ORDER BY a1.score DESC , a1.planet DESC ;[/code]
Link to comment
https://forums.phpfreaks.com/topic/16366-ranking-sql-results/
Share on other sites

If you fetch your rows with $result = mysql_fetch_row.... then
you use $result[0] for planet, $result[1] for score and $result[2] for rank.

Or you might try to name these fields with the AS in MySql, and you could address them as
$result['planet'], $result['score'] and $result['rank'].

Ronald  8)
Link to comment
https://forums.phpfreaks.com/topic/16366-ranking-sql-results/#findComment-68078
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.