Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 结果和时间表_Php_Mysql - Fatal编程技术网

Php 结果和时间表

Php 结果和时间表,php,mysql,Php,Mysql,到目前为止,我已经用谷歌电子表格完成了这项工作,但在导入范围和使其更好、更漂亮的愿望方面存在一些问题。在它看起来像这样之前: 我想用MySQL和PHP来完成这一切。我已经完成了数据库中的各种表(表:用户、类、团队、时间、国家) 到目前为止,通过web表单,我获得了MySQL表的完成时间,并在time table中更新状态,在update current_timestamp上完成时间=更新当前时间戳,我想我也有一个有效的排名系统。现在我被“时间”、“差异领导者”、“差异修正”和“速度”所困扰 到目

到目前为止,我已经用谷歌电子表格完成了这项工作,但在导入范围和使其更好、更漂亮的愿望方面存在一些问题。在它看起来像这样之前:

我想用MySQL和PHP来完成这一切。我已经完成了数据库中的各种表(表:用户、类、团队、时间、国家)

到目前为止,通过web表单,我获得了MySQL表的完成时间,并在time table中更新状态,在update current_timestamp上完成时间=更新当前时间戳,我想我也有一个有效的排名系统。现在我被“时间”、“差异领导者”、“差异修正”和“速度”所困扰

到目前为止,代码是:

$results = $mysqli->query("
   SELECT klass, nimi, synd, teamnimi, start, TIME('finish') AS finish FROM bc2014 T1 
   INNER JOIN bc2014aeg T2 on T1.bc2014_id = T2.bc2014_id
   WHERE klass = 'DS1 (1 koera toukerattavedu al.14 a.)' ");
以及:

打印“”;
echo“Klass DS1$total_tvp1”;
打印“”;
打印“”;
回声“koht klass Liikme nimi SynniaegtimstartFinishTimeDif.LeaderDif.Previous km/h”;
而($row=$results->fetch_array()){
$timestamp=strottime($row['synd']);
打印“”;
打印“.$行[“排名”]。”;
打印“.removeParanthesis($row[“klass”])”;
打印“.$row[“nimi”]”..$row[“Perekonnanimi”]”;
打印“”。$date=日期($d-m-Y',$timestamp)。“”;
打印“.$row[“teamnimi”]”;
打印“”。$行[“开始”]。';
打印“”。$row[“finish”]。';
打印“.$row[“sum('finish'-'start'类似于“]”的内容);
打印“.$row[“difleder”]”;
打印“.$row[“difprev”]”;
打印“.$row[“速度”]”;
打印“”;
和视觉:


我试图获得时间、差异、速度和工作地点。

基本上,正如我从您的代码中看到的,您使用了太多的打印命令,而不是它们。您可以对所有命令使用一次打印,这样可以减少加载时间。 要在第页中显示时间dif.leader和其余部分的问题,请查看

用它来计算你需要的任何东西

对于“Difleder”,您可能有一个单独的查询来首先查找和存储领导者的时间

或者你可以先计算结果,在那里做所有的计算,然后再做输出

编辑

首先,您可以计算sql中的运行时间,如下所示:

SELECT klass, nimi, synd, teamnimi, start, TIME('finish') AS finish, TIMEDIFF(finish, start) AS runtime
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 runtime desc
通过按计算的运行时对结果进行排序,您将获得leader作为第一条记录

接下来,您将遍历结果并计算差异,如下所示:

$html="<table>"; // add your table-header here
$firstloop = true;
$km = 4.25;   // for speed-calculation

while($row = $results->fetch_array()) {
    $timestamp = strtotime($row['synd']);
    if($firstloop) {
        $leader_runtime = $row["runtime"];
    }
    $html.='<tr>';
    $html.='<td>' .$row["ranking"].'</td>';

    $html.='<td>'.removeParanthesis($row["klass"]).'</td>';
    $html.='<td>'.$row["nimi"].'  '.$row["Perekonnanimi"].'</td>';
    $html.='<td>'.$date = date('d-m-Y', $timestamp).'</td>';
    $html.='<td>'.$row["teamnimi"].'</td>';
    $html.='<td>'.$row["start"].'</td>';
    $html.='<td>'.$row["finish"].'</td>';
    $html.='<td>'.$row["runtime"].'</td>';

    $difleader = mktime( date('H',$runtime)-date('H',$leader_runtime), date('i',$runtime)-date('i',$leader_runtime), date('s',$runtime)-date('s',$leader_runtime),0,0,0);
    $html.='<td>'. date('H:i:s', $difleader) .'</td>';

    if(isset($prev_runtime)) {  // only show difference if we have a prev_runtime set already
        $difprev = mktime( date('H',$runtime)-date('H',$prev_runtime), date('i',$runtime)-date('i',$prev_runtime), date('s',$runtime)-date('s',$prev_runtime),0,0,0);
        $html.='<td>'. date('H:i:s', $difprev) .'</td>';
    } 
    else {
        $html.= '<td></td>';
    }
    $html.='<td>'.getspeed(timetohours($row["runtime"]),$km).'</td>';
    $html.='</tr>';

    $prev_runtime = $row["runtime"];
    $firstloop = false;
}
$html.="</table>";
echo $html;
使用帮助函数计算时间戳之外的小时数:

function timetohours($t) {
  return date("G",$t)+(date("i",$t)/60)+(date("s",$t)/60/60);
}
因为我不知道你的数据库里有什么我无法测试,
时间和速度的计算已经过测试。

@Daerknight是的,我想在@Jeff页上显示它们,举个例子会很感激;)对于'Difleder'来说,这是一个令人难以置信的全面响应,但在您的示例中,当我只是复制粘贴到'$html.=''行中时,似乎出现了一些“问题”。getspeed(timetohours($row[“runtime”],$km)“;”解析错误:语法错误,意外“;”,在我写这段代码时-表的似乎.removePranthesis问题。在基础上,将“开始”作为时间格式“完成”作为时间戳表。表示例如下-bc2014_id是关于competitorI的信息或缺少一个括号来结束timtohours错误调用:getspeed(TIMETHOURES($row[“runtime”],$km)在phpMyAdmin中使用此选项“finish”值=00:00:00-使用此$html.code页无法处理.removeParanthesis($row和.getspeed($timetohours($row),我认为因为finish是0,所以运行时00:00和km/h也不会显示和不同。
function getspeed($h,$km) {
  return number_format( $km/$h , 2 );
}
function timetohours($t) {
  return date("G",$t)+(date("i",$t)/60)+(date("s",$t)/60/60);
}