查询的输出:
我现在可以输出员工登录的日期和时间。
我现在要做的是在TIMEDIFF FUNCTION
中使用时间列的输出,这样我就可以用它来计算那个人的工资。问题是我不知道如何调试此错误,非常感谢任何帮助。
以下是代码:
<!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 FROM records GROUP BY User_ID, day ORDER BY User_ID, day;";
$sql .= "SELECT TIMEDIFF('08:00:00', '07:00:00');";
// Execute multi query
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></tr>";
// output data of each row
while ($row=mysqli_fetch_row($result))
{
echo "<tr><td>" . $row[0]. "</td><td>" . $row[1].
"</td><td>" . $row[2]. "</td></tr>";
}
// Free result set
mysqli_free_result($result);
}
}
while(mysqli_more_results($con) && mysqli_next_result($con));
}
mysqli_close($con);
?>
var_dump($row)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '1' (length=1)
1 => string '14:31:24' (length=8)
2 => string '2016-09-09' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '1' (length=1)
1 => string '15:02:05' (length=8)
2 => string '2016-09-10' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '1' (length=1)
1 => string '00:48:18' (length=8)
2 => string '2016-09-12' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '1' (length=1)
1 => string '18:39:46' (length=8)
2 => string '2016-09-14' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '1' (length=1)
1 => string '18:54:04' (length=8)
2 => string '2016-09-15' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '1' (length=1)
1 => string '08:32:15' (length=8)
2 => string '2016-09-16' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '1' (length=1)
1 => string '10:06:37' (length=8)
2 => string '2016-09-17' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '1' (length=1)
1 => string '17:09:14' (length=8)
2 => string '2016-09-18' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '1' (length=1)
1 => string '12:32:52' (length=8)
2 => string '2016-09-19' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '1' (length=1)
1 => string '09:11:34' (length=8)
2 => string '2016-09-20' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '1' (length=1)
1 => string '08:35:24' (length=8)
2 => string '2016-09-21' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '1' (length=1)
1 => string '21:42:45' (length=8)
2 => string '2016-09-22' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '1' (length=1)
1 => string '10:08:21' (length=8)
2 => string '2016-09-23' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '2' (length=1)
1 => string '00:12:38' (length=8)
2 => string '2016-09-16' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '3' (length=1)
1 => string '23:52:06' (length=8)
2 => string '2016-09-15' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '4' (length=1)
1 => string '09:11:54' (length=8)
2 => string '2016-09-16' (length=10)
C:\wamp64\www\test1.php:36:
array (size=3)
0 => string '4' (length=1)
1 => string '12:22:07' (length=8)
2 => string '2016-09-21' (length=10)
C:\wamp64\www\test1.php:36:
array (size=1)
0 => string '01:00:00' (length=8)
答案 0 :(得分:0)
好吧,如果你评论这部分,你的问题就会消失。
$sql .= "SELECT TIMEDIFF('08:00:00', '07:00:00');";
此查询的输出是一个简单的数组,如下所示:
Array ( [0] => 01:00:00 )