Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!