8
With the code below I can display all users as I put DESC
and the variable $num
and increasing the placement with $num++;
.
But what if I want to take the placement/rank of the guy who’s logged in ($_SESSION)
and not everyone’s?
<?php
include "../banco_de_dados/banco_cadastro.php";
$sql= mysql_query("SELECT * FROM rank ORDER BY pontuacao DESC");
echo "<table>";
echo"<th > Colocação </th> <th> Nome </th> <th > Pontuação </th> ";
$num=1;
while ($row = mysql_fetch_array($sql))
{
echo "<tr>";
echo"<td >" . $num . "º</td>";
echo "<td > " .$row['nome'] . "</td>";
echo "<td > " .$row['pontuacao']. "</td>";
echo"</tr>";
$num++;
}
echo "</table>"; ?> </div>
The best way was to really have a spine with the ranking of each.
– Jorge B.
What are the columns of your rank table?
– Erlon Charles
I know, however as users are using the application the rank is being changed, so I cannot determine a position for them.
– I Wanna Know
The columns are: NAME to identify, EMAIL to know who is logged in and SCORE where the number can both increase and decrease. I also created the COLOCACAO field, but I don’t know how to put data in it according to the score.
– I Wanna Know
ORDER BY pontuacao DESC
? Ai just do a binary search on the ordered vector. The position in the vector will be the position in the ranking.– Beterraba