0
As the title says I’m having trouble putting a rank system from higher to lower number.
My system is in the order of the database
order in the database = 10,9,6,8,2,3 <- is in the order msm on my page.
if(isset($_POST["uid"])) {
$id = protege($_POST["uid"]);
$my = $PDO->prepare("SELECT * FROM Banco WHERE id=:id");
$my->bindValue(":id", $id);
if($my->execute()) {
if($my->rowCount() > 0) {
$fetch = $my->fetch();
$pontos = (int)$fetch["pontos"];
$pontos++;
$q = $PDO->prepare("UPDATE Banco SET pontos=:pontos");
$q->bindValue(":pontos", $pontos);
if($q->execute()) {
echo '{"pontos":"'.$pontos.'"}';
exit(0);
}
}
}
}
function pegarUsuarios() {
global $PDO;
$query = $PDO->prepare("SELECT * FROM Banco");
if($query->execute()) {
while($fetch = $query->fetch()) {
echo '<li>'.protege($fetch["id"]).'</li><li onclick=\'ponto('.protege($fetch["id"]).')\'>'.protege($fetch["name"]).'</li><li id="'.protege($fetch["id"]).'">'.protege($fetch["pontos"]).'</li>';
}
}
}
I wanted to leave in this order = 10,9,8,6,3,2
Don’t just add
ORDER BY <coluna> DESC
in your consultation?– Woss
And if the purpose of the first code is just to increase the number of points, just do something like
update Banco set pontos = pontos + 1 where id=:id
. That would avoid having to do the select just to pick up the current score value.– Woss
Our man was half potato now ''/ just needed an ORDER BY DESC points.
– ODDY
Put
ASC
the order will be increasing. For the statement you want decreasing, then you must useDESC
.– Woss