Problem to list database data

Asked

Viewed 27 times

0

I’m having trouble storing the values of ORDER BY in php, I would 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 the 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; ?>

  • What’s the problem? Returns some error?

  • Warning: mysqli_fetch_assoc() expects Parameter 1 to be mysqli_result, Boolean Given in C: xampp htdocs tcc back bank.php on line 69 the 69 line contains the while scope

1 answer

1


The ORDER this 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 function mysqli_fetch_all already returns all lines in format array associative.

  • Returns the following error: mysqli_fetch_all() expects Parameter 1 to be mysqli_result, Boolean Given

  • I changed the answer, actually ORDER was written as ORBER and was making a mistake in query.

  • Gave straight. Thank you very much and excuse the lack of attention...

  • If it worked, give a upvote and mark it as a solution to the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.