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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.