2016-09-26 127 views
0

Query OuputTIMEDIFF功能不起作用

从输出中,你可以看到,我可以选择MIN(TIME(Time))但是当我在TIMEDIFF FUNCTION使用它,它读取MIN(TIME(Time))为0,我得到的-07结果:00 :00。我想知道MIN(TIME(Time))和07:00:00的区别,以确定员工迟到的小时数。对于如何解决这个问题,有任何的建议吗?所有回复都非常感谢。对不起,英文不好。

下面的代码:

<!DOCTYPE html> 
<html> 
<head> 
<style> 
table, th, td { 
border: 1px solid black; 
} 
</style> 
</head> 
<body> 

<?php 
$con=mysqli_connect("localhost","root","","september-system"); 


// Check connection 
if (mysqli_connect_errno()) 
{ 
echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 
$sql = "SELECT User_ID, MIN(TIME(Time)) as time, DATE(Time) as day, TIMEDIFF('MIN(TIME(Time))', '07:00:00')as tdiff FROM records GROUP BY User_ID, day ORDER BY User_ID, day;"; 



if (mysqli_multi_query($con,$sql)) 
{ 
do 
{ 
// Store first result set 
if ($result=mysqli_store_result($con)) { 
    echo "<table><tr><th>USER ID</th><th>TIME</th><th>DATE</th><th>ABSENCES</th></tr>"; 
// output data of each row 
    while ($row=mysqli_fetch_row($result)) 
    { 
    //echo var_dump($row); 
    echo "<tr><td>" . $row[0]. "</td><td>" . $row[1]. "</td><td>" . $row[2]. "</td><td>" . $row[3]. "</td></tr>"; 
    } 
    // Free result set 
    mysqli_free_result($result); 
    } 
} 
while(mysqli_more_results($con) && mysqli_next_result($con)); 
} 

mysqli_close($con); 
?> 
+0

我没有检查,但我可以先说变量,然后在它们之间做出不同。 – Virb

+0

@Virb我该怎么做?我真的很抱歉,我是PHP新手,我一直在做的是搜索网络。 –

回答

0

我觉得这是更好地从第一个参数 让我们试着去掉单引号,我不知道

TIMEDIFF(MIN(TIME(Time)), '07:00:00')as tdiff