Forum Moderators: coopster
no worries about your english, I understood just fine.
You don't really need to order them in the table but you can easily order them on select. Something like
select * from mytable order by ranking desc
this query would give you all of your results in order highest to lowest score. Then you could use a loop to output them and use a counter to put their rank beside them.
or is it necessary to put the rank in the table?
The ranking would be done better by simple php:
<?php
$ask = "SELECT name, score FROM table ORDER BY score DESC;//desc means that the highest is the first. You can add LIMIT 20 - only first 20 will be shown.
$conn = mysql_connect("dbhost", "dblogin", "dbpassword") or die(mysql_error());
mysql_select_db("dbname", $conn) or die(mysql_error());
$query = mysql_query($ask, $conn) or die(mysql_error());
if(mysql_num_rows($query)) {
$rank = 0;
$old_score = "";
while($answer = mysql_fetch_array($query, MYSQL_BOTH))//so you can write $answer[0] and $answer['name'] {
if(($score = $answer['score']) == $old_score) echo $rank." exequo";
else echo ++$rank;
echo ", .$answer['name'].", $score<br>";//it should be done in tds, but you'll manage
$old_score = $score;
}}
?>