How to invert the loop result order in PHP? [duplicate]

-1

I wrote a code based on tutorials that I saw to show user information database information in tables but I would like it to reverse the order of the results. How can I do this?

<?php

// se o número de resultados for maior que zero, mostra os dados

if($total > 0) {

    // inicia o loop que vai mostrar todos os dados

    do {

?>

        <table>

            <tr>

                <td>ID</td>

                <td id="um"><?= $linha['coment_id']?></td>

            </tr>



            <tr>

                <td>Veiculo</td>

                <td id="um"><?= $linha['mododeuso']?></td>

            </tr>



            <tr>

                <td>Nome</td>

                <td id="um"><?=$linha['user_name']?></td>

            </tr>



            <tr>

                <td>Email</td>

                <td id="um"><?=$linha['user_email']?></td>

            </tr>



            <tr>

                <td>Comentario</td>

                <td id="um"><?=$linha['comentario']?></td>

            </tr>

        </table><br><hr>



<?php

    // finaliza o loop que vai mostrar os dados

    }while($linha = mysql_fetch_assoc($dados));

// fim do if 

}

?>
    
asked by anonymous 09.10.2016 / 17:42

1 answer

1

In your code that has QUERY to select the information of the bank enter the option ORDER BY table_name_que_voce_query DESC;

Example:

$query = mysqli_query($dbc, "SELECT * FROM nome_da_tabela WHERE nome_da_tabela_que_voce_quer_ordenar = 'XXXXX' ORDER BY nome_da_tabela_que_voce_quer_ordenar DESC;");
    
09.10.2016 / 20:21