PHP,Javascript-从给定日期的mySQLi数据库启动计时器

时间:2019-03-15 22:00:53

标签: javascript php html5 mysqli timer

我想在仪表板上显示一个计时器。我正在开发票务管理系统中的一个部分,即实时监控。

我当前的部分是这个:

<div class="card-body p-0">
  <div class="table-responsive">
    <table class="table m-0">
      <thead>
      <tr>
        <th># Ticket</th>
        <th>Technician</th>
        <th>Status</th>
        <th>Time elapsed from assigned time</th>
        <th>Assigned Time</th>
      </tr>
      </thead>
      <tbody>
       <?php
          $tickets = array();{
              $tickets = TicketData::getAllToDo();              
          }
          if (count($tickets) > 0) {
              // if there are tickets opened
          ?>
       <?php
          foreach ($tickets as $ticket) {
             $project = $ticket->getProject();
             $events = TicketData::getEvents();
          ?>
       <?php $ticketStatus = $ticket->getStatus()->name; ?>
       <tr>
         <td><a href="index.php?view=viewticket&id=<?php echo$ticket->id; ?>"><?php $ticketId=$ticket->id; echo $ticketId; ?></a></td>
         <td><?php echo $ticket->getUser()->name." ".$ticket->getUser()->lastname; ?></td>
         <td>
          <?php if($ticketStatus=="In Process"){
          echo "<span class='badge badge-warning'>".$ticketStatus."</span>";
          }elseif ($ticketStatus=="Pending") {
             echo "<span class='badge badge-danger'>".$ticketStatus."</span>";
          }
          ?>
        </td>
        <td>
          <?php
            $newCon = new Database();
            $con = $newCon->connect();
            $assignedToTecnico = "SELECT id, SUM(TIMESTAMPDIFF(MINUTE,convert(time_at,time),convert(visit_hour_in, time))) as tiempo, (TIMESTAMPDIFF(MINUTE,convert(time_at,time),convert(visit_hour_in, time))/COUNT(tecnico_id)) as average FROM ticket where id=".$ticketId;
            $query = $con->query($assignedToTecnico);   
            $row = $query->fetch_row();
            $time= $row[2];
            $timesec= ($time)*60;
            $days = floor($timesec / (60 * 60 * 24));
            $timesec -= $days * (60 * 60 * 24);
            $hours = floor($timesec / (60 * 60));
            $timesec -= $hours * (60 * 60);
            $minutes = floor($timesec / 60);
            $timesec -= $minutes * 60;
            $seconds = floor($timesec);
            $timesec -= $seconds;
            if ($days==0 && $hours==0 && $minutes==0) {
               echo "The technician hasn't visited the client yet.";
            }else{ 
               echo "{$days} days, {$hours} hours, {$minutes} minutes.";
            }
            ?>
        </td>
        <td>
          <?php echo$ticket->time_at; ?>
        </td>
       </tr>
       <?php } ?>
       <?php
          } else {
              echo "<p class='alert alert-danger'>No hay tickets abiertos</p>";
          }
       ?>
      </tbody>
    </table>
  </div>
</div>

我现在正在打印静态表,我的PHP代码将显示从分配票证到现在所经过的时间。

但是,我们希望有一个 running 计时器,该计时器将在技术人员每次登录时停止,而不是文本The technician hasn't visited the client yet.

我看到this answer遇到了类似的问题,this question试图解决我要说明的问题。

我尝试使用后者,而我在该字段中得到的只是这样:

  

NaN

我该如何实现?

0 个答案:

没有答案