Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Time online register Loop & Includes (homework help)

I have this page with a stop and pause button and I need store user online activity time in minutes on a mysql DB after click on start button. What would be the simplest and most effective way to do this? according to your opinion

Mechanism: The way that I found is send a POST every minute from the hit of button start. If I hit button start and stay on page for 30 minutes this code should add 30 times the value 1 in "timevalue". By this way the total online time will be stored in minutes

Problems: When load page automatically add value 1 on DB, because monitoring.php is loaded together main page

How to assure call the include only after start button click?
How to unload or stop monitor div after stop button?
How to loop this function? setInterval isn't working

counter.php

<?php

//value for test purposes
$result = "get from db"

?>
<!DOCTYPE html>
<html>
<head>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <title>ONLINE TIME</title>
</head>

<script type="text/javascript">
//window.setInterval(function () {executemonitor()}, 1000);

function executemonitor() {
    $("#monitor").load("monitoring.php");
}
</script>

<body>
   Total Online Time: <?php echo "$result" ?>
<br>
<form method="POST"> 
<button type="submit" class="start-trigger" onclick="executemonitor()">START</button>
<br><br>
<button class="stop-trigger" onclick="">STOP</input>
<div id="monitor" class="monitoring"><?php include "monitoring.php" ?></div>
</form>
</body>
</html>

monitoring.php

<?php

//set value for test purposes
$timeactivityf = "1";

$servername = "localhost";
$database = "timejob";
$username = "tmj";
$password = "tmj";

$conn = mysqli_connect($servername, $username, $password, $database);
     
     $sql = "INSERT INTO user (timeactivity)
     VALUES ('$timeactivityf')";
     if (mysqli_query($conn, $sql)) {
    //   echo "New record has been added successfully !";
     } else {
     //   echo "Error: " . $sql . ":-" . mysqli_error($conn);
     }
     mysqli_close($conn);

//window.setInterval(function () {executemonitor()}, 1000);

?>

Thanks

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda