How to update the result of a PHP page to each insert made in the database?

0

I'm a beginner on the subject, but I'll try to explain what I want to do in the best way. I would like to update my WEB page, every time there is a new insert the database. Below I will post my code, I'm starting to like your help.

<?php

include("config/config_hospital.php");

date_default_timezone_set('America/Maceio');
$data = date('d/m/Y   |  H:i');
//echo $data;

$result = pg_query("SELECT * FROM chamapainel2 ORDER BY id_codigo DESC LIMIT 1");
$result2 = pg_query("SELECT * FROM chamapainel2 ORDER BY id_codigo DESC LIMIT 3");
$result3 = pg_query("SELECT * FROM chamapainel2 ORDER BY id_codigo DESC LIMIT 1");

while ($row = pg_fetch_assoc ($result3)) {
    $ultimo_id=$row['id_codigo'];
}

while ($row = pg_fetch_assoc ($result)) {

             if($ultimo_id == $row['id_codigo']){

              echo '<table width="100%" border="0" align="center" id='tabela'>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>            
              <b><p style="font-size: 55px" align="center"><FONT FACE="Verdana"> ' . $row['nome_paciente'] . '
              <p style="font-size: 45px" align="center"><FONT FACE="Verdana">LOCAL: TRIAGEM
              <p style="font-size: 45px" align="center"><FONT FACE="Verdana">MÉDICO: CLÍNICO GERAL
              <br>
              </table>';

                echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>';echo'<audioid="notificacao" preload="auto">
                <source src="sons/aero.wav" type="audio/mpeg">
                </audio>';  
} else {
    exit;
    }
}           

    # Tabela da listagem...
            echo'
            <table class="table table-hover" width="100%">
                <thead>
                    <th width="5%" colspan="3"><font size="5" <center>ÚLTIMOS ATENDIMENTOS NA UNIDADE UMSAM:</center></font></th>
                </thead>
                <thead>
                    <th width="5%" colspan="3"><font size="5" <center></center></font></th>
                </thead>
                    <th width="5%"><center>NOME</center></th>
                    <th width="5%"><center>LOCAL ATENDIMENTO</center></th>
                    <th width="5%"><center>MÉDICO</center></th>
                </thead>
                <tbody>';

while ($row = pg_fetch_assoc ($result2))  

           {
             //if ($row['id_codigo'] == ($row['id_codigo'] {

                 echo "<tr>\n";
                        echo "<td>". $row["nome_paciente"] ."</td>\n";
                        echo "<td align=\"center\">TRIAGEM</td>\n";
                        echo "<td align=\"center\">CLÍNICO GERAL</td>\n";
                        echo("");
                    echo "</tr>\n";


    }   

    ?>

<script type="text/javascript" src="js/jquery.js"></script>

       <script type="text/javascript">
    $(document).ready(function(){
        atualiza();
    });

    function atualiza(){
       $.get('atualizapainel.php', function(resultado){
        $('#tabela').html(resultado);
       })
       setTimeout('atualiza()', 3000);
    }
   </script>
<script>
i = 1;

setInterval(function() {

  $('x-contador').text(5 - i);

  if (i != 5) {
    $('#notificacao').trigger('play');
    i = 5;
  }
}, 1000);
</script>
    
asked by anonymous 26.05.2018 / 02:50

0 answers