0

I am trying to update the data inside the element every few seconds but the element completely disappears and I can't even see it

here is my code:

setInterval(function(){

$policeunits1 = $client->test->units;
$policeunit1 = $policeunits1->findOne(
    ['name' => 'police1']
);

$person1 = $policeunit1->id;
$status1 = $policeunit1->status;
if (!empty($status1)) $status1 = "<h2 style='color: yellow'>Code-7</h2>";
if (empty($status1)) $status1 = "<h2 style='color: white'>Code-9</h2>";


echo"<div class='dashboard'>
<div class='units'>
<div class='unitsheader'>
<div class='unitheadsep'></div>
<h>Units</h>
</div>";

setInterval(function(){

if (!empty($person1)) {
echo"<div class='unit1'>
<div class='unitseperator'></div>
<h1>$person1 : </h1>$status1
</div>";
}


},5000);


I tried to set interval and I expected that the element's data will keep on updating each 5 seconds
ADyson
  • 57,178
  • 14
  • 51
  • 63
  • Php code only runs on the server when your page is loading. It does not run in the browser and dynamically update your page. If you want that you need to use javascript (which already has a built-in setInterval function) – ADyson Nov 26 '22 at 08:46

0 Answers0