Jump to content

Archived

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

truCido

Ranking SQL results?

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]

Share this post


Link to post
Share on other sites
What columns exectly do you want to display? In a HTML table?

Ronald  8)

Share this post


Link to post
Share on other sites
I want to display Planet in one column, score in another and then rank in another as well, its not the html that I can't do its the presenting the results from the query

Share this post


Link to post
Share on other sites
$row['rank'] will be the rank column, or $row[2] if you use mysql_fetch_row

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

×

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.