Problem to list bank data

0

I'm having trouble storing the values of ORDER BY in php, I'd like to store them in an array and show it on another page.

Database file with function:

    function buscar_rank($conexao) {
    $sqlBusca = 'SELECT * FROM usuario ORBER BY pontos;';
    $resultado = mysqli_query($conexao, $sqlBusca);

    $usuarios = array();

    while ($rank = mysqli_fetch_assoc($resultado)) {
        $usuarios[] = $rank;
    }

    return $usuarios;
}

file where you would like to store results

<table>
   <tr>
       <?php $lista_rank = buscar_rank($conexao); 

       foreach($lista_rank as $rank) :
       ?>
       <td><?php echo $rank['nome']; ?></td>
       <td><?php echo $rank['pontos']; ?></td>
   </tr>
   <?php endforeach; ?>

    
asked by anonymous 25.05.2018 / 22:00

1 answer

1

ORDER is spelled wrong, change to:

$sqlBusca = 'SELECT * FROM usuario ORDER BY pontos;';

You can also improve your function by changing to:

function buscar_rank($conexao) {
    $sqlBusca = 'SELECT * FROM usuario ORDER BY pontos;';
    $resultado = mysqli_query($conexao, $sqlBusca);

    return mysqli_fetch_all($resultado, MYSQLI_ASSOC);
}

The mysqli_fetch_all function already returns all rows in% associative% format.

    
25.05.2018 / 22:11