Find Difference between leader and Previous in results table

后端 未结 2 1187
攒了一身酷
攒了一身酷 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: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 ''. $row["elapsed_time"] - $leader_time .'s';
        print ''. $row["elapsed_time"] - $last_time .'s';
      } else { 
        print ' ';
        print ' ';
      }
    // ...
      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

提交回复
热议问题