简体   繁体   English

表中每一行的计时器

[英]Timer in Every Row of Table

I would like to add a running time/ stopwatch for every row showing the time spent in each process.我想为每一行添加一个运行时间/秒表,显示每个进程所花费的时间。 The timer just shows at the first row and nothing on the rest.计时器只显示在第一行,其余没有。

The date to be used would come from a database.要使用的日期将来自数据库。

Here's a snippet of my code for reference:这是我的代码片段供参考:

<?php
  
  echo "<h2>On-Going Repairs</h2>";

  $query = "SELECT tca_ro, tca_csplate, tca_name, tca_start, tca_process FROM tcs.tca_bp_process WHERE date(tca_start) = curdate() AND tca_status = 'Started'";

  if($query_result = mysqli_query($link,$query)){

    if(mysqli_num_rows($query_result) > 0)
    {
        echo "<div class='card-body'>";
            echo "<div class='table-responsive'>";
                echo "<table class='table table-bordered' id='dataTable' width='100%' cellspacing='0'>";
                    echo "<thead>";
                        echo "<tr>";
                            echo "<th>RO NUMBER</th>";
                            echo "<th>CS NUMBER</th>";
                            echo "<th>TECHNICIAN</th>";
                            echo "<th>START</th>";
                            echo "<th>PROCESS</th>";
                            echo "<th>DURATION</th>";
                        echo "</tr>";
                    echo "</thead>";

                    echo "<tbody>";

                    while ($row = mysqli_fetch_array($query_result))
                    {
                        echo "<tr>";
                            echo "<td>".$row['tca_ro']."</td>"; 
                            echo "<td>".$row['tca_csplate']."</td>";
                            echo "<td>".$row['tca_name']."</td>";
                            echo "<td><input type='text' id='date' value='".$row['tca_start']."'</td>";
                            echo "<td>".$row['tca_process']."</td>";
                            echo"<td><div id='data'></div></td>";
                        echo "</tr>";
                    }                                    
                    echo "</tbody>";
                echo "</table>";
              echo "</div>";
        echo "</div>";
    } 
  }
?

  <script type="text/javascript">
    function func(){

      var dateValue = document.getElementById("date").value;
      var date = Math.abs(new Date(dateValue).getTime() / 1000).toFixed(0);
      var currentDate = Math.abs((new Date().getTime() / 1000).toFixed(0));
      var diff = currentDate - date;

      var hours = Math.floor(diff/3600) % 24;
      var minutes = Math.floor(diff/60) % 60;
      var seconds = diff % 60;

      var time_str = hours + " : " + minutes +" : "+ seconds

      document.getElementById("data").innerHTML =hours+":"+minutes+":"+seconds;
    }

    func();
    setInterval(func, 1000);
  </script>

Hope you can help me out.希望你能帮助我。 Thank you in advance先感谢您

You have no need for Timer as they are in the Java programming language.您不需要 Timer,因为它们在 Java 编程语言中。 All you need to do is display the values from a database.您需要做的就是显示数据库中的值。

Assuming you have start and end times in tca_start and tca_end, and duration in tca_duration just add lines as假设您在 tca_start 和 tca_end 中有开始和结束时间,并且在 tca_duration 中有持续时间,只需将行添加为

echo "<td>".$row['tca_start']."</td>";
echo "<td>".$row['tca_end']."</td>";
echo "<td>".$row['tca_duration']."</td>";

If that is not what you are looking for, maybe enhance you question.如果那不是您要寻找的,也许可以增强您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM