0
I am a beginner in the subject, but I will try to explain in the best way what I intend to do. I would like to update my web page, every time there is a new database Insert. Below I will post my code, I’m starting I would 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 '<audio id="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>
How about using Websockets?
– Laércio Lopes
I do not know, but I researched one about when you mentioned, I did not find much documentation outside the main site and never used this tool, could give me an example with this tool how to update the page to each Internet held in the database?
– Douglas Farias
I only gave you this reference because it is the type of technology used when you need to receive a response from the server without having to make the request at all times, otherwise you would have to request the server from time to time to check if you have a new record. I don’t use it in any project to give you an example.
– Laércio Lopes
I get it. Even thanks for the tip!
– Douglas Farias