Return of consultation in descending order

Asked

Viewed 67 times

0

With this code, how do I make the return of the query come in order decreasing?

<?php
session_start();
include_once "conexao.php";
?>
<!DOCTYPE html>
<html lang="pt-br">
    <head>
        <meta charset="utf-8">
        <title>CRUD - Pesquisar</title>     
    </head>
    <body>
    <center>
        <a href="http://localhost/aula/index.php">
<button> Menu </button> </a>


        <h1>Pesquisar Pré Picking</h1>
        <?php
        if(isset($_SESSION['msg'])){
            echo $_SESSION['msg'];
            unset($_SESSION['msg']);
        }
        ?>
        <form method="POST" action="">
            <label>Nome: </label>
            <input type="text" name="nome" placeholder="Digite o nome"><br><br>

            <input name="SendPesqUser" type="submit" value="Pesquisar">
        </form><br><br>

        <?php
        $SendPesqUser = filter_input(INPUT_POST, 'SendPesqUser', FILTER_SANITIZE_STRING);
        if($SendPesqUser){
            $nome = filter_input(INPUT_POST, 'nome', FILTER_SANITIZE_STRING);
            $result_usuario = "SELECT * FROM pessoas1  '; WHERE nome LIKE '%$nome%  ORDER BY `data` DESC";
            $resultado_usuario = mysqli_query($conn, $result_usuario);
            while($row_pessoas1 = mysqli_fetch_assoc($resultado_usuario)){
                 echo "ID:" . $row_pessoas1['id'] . "<br>";
                  echo "Nome:" . $row_pessoas1['nome'] . "<br>";
                  echo "Rua:" . $row_pessoas1['rua'] . "<br>";
                  echo "Tipo:" . $row_pessoas1['tipo'] . "<br>";
                  echo "Lista:" . $row_pessoas1['lista'] . "<br>";
                  echo "Data:" . $row_pessoas1['data'] . "<br><hr>";
                echo "<a href='edit_usuario.php?id=" . $row_pessoas1['id'] . "'>Editar</a><br><hr>";

            }
        }
        ?>
        </center>
    </body>
</html>
  • You do not have this ; before WHERE. O ; indicates the end of an SQL command.

  • sorry I didn’t understand that ordr by I put no more god right deconsidere it

  • what the code I sent would look like

  • $result_usuario = "SELECT * FROM people1 WHERE name LIKE '%$name%' ORDER BY data DESC;";

  • Note 1,000 worked 100% thank you very much !!!

  • as resolved, it is worth putting the solution as an answer so that the question does not remain open (why accept an answer) ;)

Show 1 more comment

1 answer

0

As I put in the comment, so that the question does not go unanswered, I will put the suggested here


The mistake is '; before the where; the consultation shall be as follows::

$result_usuario = "SELECT * FROM pessoas1 WHERE nome LIKE '%$nome%' ORDER BY data DESC;"; 

Browser other questions tagged

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