编辑:(添加表格示例)
有了你的帮助,我就在这个地方,我有表格中的信息(姓名,团队,开始时间结束时间,甚至是这两者之间的时间。感谢@Ian Kenney;) solution to find time between start & finish
现在我如何计算和显示领导者与之前的差异之间的页面差异。
当前的工作查询是:
query("
SELECT
klass, nimi, synd, teamnimi, start,
TIME(`finish`) AS finish,
timediff(time(finish), time(start)) AS aeg
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");
和输出是这样的:
表格如下:
echo "<tr><th>koht </th><th>klass </th><th>Liikme nimi </th><th>Synniaeg</th><th>Tiim</th><th>Start</th><th>Finish</th><th>Time</th><th>Dif.Leader</th><th>Dif.Previous</th><th>km/h</th></tr>";
while($row = $results->fetch_array()) {
$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>';
print '<td>'.$row["speed"].'</td>';
print '</tr>';
}
答案 0 :(得分:0)
$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>';
了解更多格式: http://php.net/manual/en/function.date-diff.php
下面的代码应该按照你的要求进行
{{1}}
答案 1 :(得分:0)
你可以通过记住领导时间和前一个循环时间来计算领导者的差异。
允许在查询中添加elapsed_time
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
然后在结果集中使用它来计算时差
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"] ;
}
然后您可以使用$ leader_time和$ last_time来计算两个差异列