doulong4169 2018-03-21 14:24
浏览 306

使用数据库倒计时的php / mysql计时器

please I need help with counter (timer) that use table data as minutes to count. For example, i table i have row that sets number 5 (it will always be in minutes) and on php page i have table with some rows. i need to create on every row Start/End button. Clinking on Start will user value from table and start counting 5:00, 4:59 etc. Problem is that timer should not reset after refresh page (many people will look at this page).

I have this script that calculates start time and end time, but it will reset after refresh.

I did not post while table with rows, I did not think it is necessary. in table, output of column that contain minutes is

<?php echo $row['Trajanje_pauze'] ; ?>

this is my script, i found on this link

 <?php
    session_start();
    ?>
    <form action="msa_pauze.php" method="POST">
         <td> <input type="submit" name="start" value="Start"></td>
           <br><br>
         <td> <input type="submit" name="end" value="End"></td>
        </form> 
    <?php 

if(isset($_POST['start'])) {
    date_default_timezone_set('Europe/Zagreb'); 
    $time_start = date('Y-m-d H:i:s'); 
    $_SESSION['start'] = $time_start;
    echo "time start now $time_start <br>";
}

if(isset($_POST['end'])) {
    date_default_timezone_set('Europe/Zagreb'); 
    $time_end = date('Y-m-d H:i:s'); 
    $_SESSION['end'] = $time_end;
    echo "time was ended $time_end <br>"; 
    $sst= new DateTime($_SESSION['start']);
    $eet= new DateTime($_SESSION['end']);
    $diff = date_diff($eet, $sst);
    $timeelapsed = $diff->format('%r %a days, %h hours, %i minutes and %S seconds');
    echo $timeelapsed;
}
    ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?