I have a PHP page that every x seconds consults another PHP the number of rows of a query. Based on that answer, that is, if the value is greater than zero, I would like to show a div
, which is an alert, which should be intermittent.
I have half accomplished it, I need to load the page to check if there are more than 0 rows and only show the div
with the number of rows if it is greater than 0. Also give some more verbose flicker than I achieved. After the page loads, I would like it to be verified every 60 seconds.
I copy what I achieved, the most important thing:
function actualizar() {
$('#sensor').fadeIn("slow").load('prueba1.php');
}
setInterval("actualizar()", 5000);
#contiene_sensor {
position: absolute;
text-align: center;
overflow: hidden;
top: 10px;
right: 320px;
width: 80px;
height: 80px;
z-index: 29999;
}
#sensor {
position: relative;
line-height: 80px;
display: block;
top: -82px;
left: -2px;
margin: 0 auto;
max-width: 40px;
font-family: "Arial Black", bold;
color: white;
font-size: 26px;
text-shadow: -1px 4px 29px rgba(150, 150, 150, 1);
z-index: 30001;
}
#luxecita {
z-index: 30000;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="contiene_sensor">
<img id="luxecita" style="width:80px; height:80px;" src="https://placehold.it/80x80/green" />
<span id="sensor"></span>
</div>
And test1.php has the following code:
<?php
if ($result=mysqli_query($conn_alertas,'SELECT COUNT(*) FROM alertas')) {
$rowcount = $result->fetch_row();
echo $rowcount[0];
mysqli_free_result($result);
}
mysqli_close($conn_alertas);
?>
In case it was not understood:
count
is greater than 0 I show the div
with the number of rows count
is 0, I do not show the div