Find Difference between leader and Previous in results table

后端 未结 2 1130
攒了一身酷
攒了一身酷 2021-01-26 00:15

Edited: (added table example)

With your help guys I\'m in this place that I have information in table ( Name, team, start time finish time and even time between these tw

相关标签:
2条回答
  • 2021-01-26 00:27
    $date2 = date_create($date2InString);
    $date1 = date_create($date1InString);
    date_diff($date2, $date1)->format('%h %i %s' );
    

    for more formats: http://php.net/manual/en/function.date-diff.php

    below code should do what you asked for

    $timestamp = strtotime($row['synd']);
     print '<tr>';
      print '<td>' .$row["ranking"].'</td>';
     print '<td>'.removeParanthesis($row["klass"]).'</td>';
       print '<td>'.$row["nimi"].'  '.$row["Perekonnanimi"].'</td>';
         print '<td>'.$date = date('d-m-Y', $timestamp).'</td>';
        print '<td>'.$row["teamnimi"].'</td>';
    print '<td>'.$row["start"].'</td>';
    print '<td>'.$row["finish"].'</td>';
    print '<td>'.$row["aeg"].'</td>';
    print '<td>'.$row["difleader"].'</td>';
    print '<td>'.$row["difprev"].'</td>';
    $date2 = date_create($row["difprev"]);
    $date1 = date_create($row["difleader"]);
    date_diff($date2, $date1)->format('%h %i %s' );
    print '<td>'.$row["speed"].'</td>';
     print '</tr>';
    
    0 讨论(0)
  • 2021-01-26 00:41

    you can work out the diff from leader by remembering the leaders time, and the previous time as you run through the loop.

    lets add an elapsed_time into the query

    SELECT 
     klass, nimi, synd, teamnimi, start, 
     TIME(`finish`) AS finish,
     timediff(time(finish), time(start)) AS aeg,
     finish - start as elapsed_time
    FROM bc2014 T1 
    INNER JOIN bc2014aeg T2 on T1.bc2014_id = T2.bc2014_id
    WHERE klass = 'DS1 (1 koera toukerattavedu al.14 a.)'
    ORDER BY aeg
    

    Then use this in the result set to calculate the time differences

    while($row = $results->fetch_array()) {
    //.....
    
      if(isset($leader_time)){
        print '<td>'. $row["elapsed_time"] - $leader_time .'s</td>';
        print '<td>'. $row["elapsed_time"] - $last_time .'s</td>';
      } else { 
        print '<td> </td>';
        print '<td> </td>';
      }
    // ...
      if(!isset($leader_time)){ $leader_time = $row["elapsed_time"] ;} 
      $last_time = $row["elapsed_time"] ;
    }
    

    you can then use $leader_time and $last_time to calculate the two difference columns

    0 讨论(0)
提交回复
热议问题