I am creating a website with an ELO rating system on it. Luckily, I found a nice template to follow and have most of the website complete… except for some reason it didn’t come with a numbered player ranking. So i’ve been scratching my head (not that good at php) to come up with code that will work. I have been successful for the most part and have something that works… it just doens’t work correctly.
$SQL = " SELECT * FROM ratings WHERE `active`=1 ORDER by rating desc ";
$retid = mysql_db_query($db, $SQL, $cid);
$rank = 1;
if (!$retid) { echo( mysql_error()); }
?>
<?php
while ($row = mysql_fetch_array($retid)) {
$sql_m="UPDATE `ratings` SET `rank`=$rank";
mysql_db_query($db,"$sql_m",$cid);
$rank++;
}
This is my code. It runs and compiles fine, however, instead of giving the first player rank 1 and second rank 2, third 3, etc… it gives them all the final number (which is 12 at the moment). So everyone ends up at rank 12! help!