How to invert the order of loop results in PHP?

Asked

Viewed 422 times

-1

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

<?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 

}

?>

1 answer

1


In your QUERY code to select the database information enter the ORDER BY option nome_da_tabela_que_voce_quer_ordenar 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;");

Browser other questions tagged

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