I have a highscore table that has three columns, name, highScore, rep. Currently I loop through the results ORDERED by rep. I have an $i est within the loop and this displays as rank eg:
SELECT highScore, name, rep FROM table1 ORDER BY rep DESC
while ($row = $result->fetch_assoc())
{
echo "<tr>";
echo "<td>" . $i . "</td>"; // rank
echo "<td>" . $row["name"] . "</td>"; // name
echo "<td>" . $row["rep"] . "</td>"; // rep
echo "<td>" . $row["highScore"] . "</td>"; // high score
echo "</tr>";
$i++;
}
}
Currently this works without fault. The problem is that i have now implemened a "sort by" button which changes the SQL to ORDER to highScore
instead of rep
. the only problem is that the Rank does not match now. Is there a way of getting and echoing the position of each row based on rep
and then seslcting and ordering based on highScore
?