PHP data collection and inserting mysql data

Asked

Viewed 186 times

0

I’m trying to collect data from the last section inserted via PHP in Mysql, which shows on the screen the last (id, Nome, Idade) etc. of query inserted.

page after inclusion should appear this fields below the page select

<!DOCTYPE html>
<html>
  <head>
      <title>Selecione</title>
      <meta charset="utf-8">
  </head>
  <body>

    <?php

       //niciando a conexão com o banco de dados
       $cx = mysqli_connect("127.0.0.1", "root", "");

       //selecionando o banco de dados
       $db = mysqli_select_db($cx, "itil");


        //criando a query de consulta à tabela criada
        $sql = mysqli_query($cx, "SELECT * FROM glpi_change_new") or die(
         mysqli_error($cx) //caso haja um erro na consulta
        );

        //pecorrendo os registros da consulta.
        if($aux = mysqli_fetch_assoc($sql), === TRUE)  {
           $last_id = $aux->insert_id;
           echo "<h3>GMUD incluida com sucesso! GMUD n°: </h3>" . $last_id;

           echo "-----------------------------------------<br/>";
           echo "ID:" ; $aux["idglpi_change_new"] . "<br />";
           echo "Nome:" . $aux["tNome"] . "<br />";
           echo "Email:" . $aux["tEmail"] . "<br />";
           echo "Tel: " . $aux["tTel"] . " ";
           echo " Cel: " . $aux["tCel"] . "<br />";
           echo "Unid: " . $aux["tUnid"] . " ";
           echo " Departamento: " . $aux["tDepartamento"] . "<br />";
           echo "Data da Execução: " . $aux["tDate"] . "<br />";
           echo "Cliente: " . $aux["tCliente"] . "<br />";
           echo "Detalhe da origem: " . $aux["t_dtorigem"] . "<br />";
           echo "Mudança: " . $aux["tMudança"] . "<br />";
           echo "Descrição da Mudança: " . $aux["tDescmud"] . "<br />";
           echo "Risco Execução: " . $aux["tRiscExec"] . "<br />";
           echo "Controle de Backup: " . $aux["tContrback"] . "<br />";
           echo "Tempo de Recuperação: " . $aux["tTempodeRec"] . "<br />";
           echo "Plano de ação para Execução: " . $aux["tPlanodeacaopexec"] . "<br />";
           echo "Urgencia porque: " . $aux["tUrgpq"] . "<br />";

    ?>

1 answer

0


I believe that in this case, from what I understood it is just order your search to limit it, always returning the last record of the table:

    $qry = "SELECT * FROM glpi_change_new ORDER BY idglpi_change_new DESC LIMIT 1";
    $sql = mysqli_query($cx, $qry  or die(
             mysqli_error($cx) //caso haja um erro na consulta
            );

Browser other questions tagged

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