Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda