我有一个表“dtr”,其中包含 6 列,即名称、ACNo、日期、时间、状态和异常。
Name | ACNo. | Date | Time | State | Exception|
-------------+-------+-----------+--------------+------------+----------+
Johnny Starks| 1220 | 5/13/2013 | 11:45:18 PM | Check In | OK |
Johnny Starks| 1220 | 5/14/2013 | 12:46:58 AM | Out | Out |
Johnny Starks| 1220 | 5/14/2013 | 12:52:41 AM | Out Back | Out |
Johnny Starks| 1220 | 5/14/2013 | 02:12:50 AM | Out | Out |
Johnny Starks| 1220 | 5/14/2013 | 02:43:11 AM | Out Back | Out |
Johnny Starks| 1220 | 5/14/2013 | 05:46:58 AM | Out | Out |
Johnny Starks| 1220 | 5/14/2013 | 06:22:41 AM | Out Back | Out |
Johnny Starks| 1220 | 5/14/2013 | 06:55:12 AM | Check Out | OK |
Johnny Starks| 1220 | 5/14/2013 | 11:47:13 PM | Check In | OK |
Johnny Starks| 1220 | 5/15/2013 | 12:36:28 AM | Out | Out |
Johnny Starks| 1220 | 5/15/2013 | 12:59:11 AM | Out Back | Out |
Johnny Starks| 1220 | 5/15/2013 | 03:12:54 AM | Out | Out |
Johnny Starks| 1220 | 5/15/2013 | 03:33:31 AM | Out Back | Out |
Johnny Starks| 1220 | 5/15/2013 | 06:55:12 AM | Check Out | OK |
所以,我想使用下面的代码得到的结果是......或者我希望循环执行的序列......
在第一个循环中-它将获得 1 个签入然后移动到第二个循环-在签入和签出后将获得签出..它现在将进入第三个/最后一个循环-这将是将使用第一个和第二个循环的结果范围获得 Breaks(带有 Out Exception 的那个)。
我这样做是为了计算每一个 (1) 班次中的每一对 Out 和 Outbreak(从签到到签出)。之后,我可以计算一 (1) 个班次的总休息分钟/小时。
我不能仅仅基于日期的班次范围。因为如果我这样做了,其他休息时间将在另一个/下一个班次,该班次的入住日期与休息日期相同,我无法正确计算或计算它所拥有的每一对休息时间。
但似乎我做错了。我应该怎么做才能得到正确的结果?或者让循环正确...
<?php
include 'connection.php';
$checktime='';
$outtime = '';
$isql = mysql_query("Select * from dtr where ACNo = '1220' and
State = 'Check In'") or die(mysql_error());
while($irow = mysql_fetch_array($isql)){
$iID = $irow['ACNo'];
$iDate = $irow['Date'];
$iTime = $irow['Time'];
$iState = $irow['State'];
if($iState == 'Check In'){
$checktime = $iTime;
$indate = $iDate;
}
$osql = mysql_query("Select * from dtr where ACNo = '1220' and
State = 'Check Out'") or die(mysql_error());
while($orow = mysql_fetch_array($osql)){
$oID = $orow['ACNo'];
$oDate = $orow['Date'];
$oTime = $orow['Time'];
$oState = $orow['State'];
if($oState == 'Check Out'){
$outtime = $oTime;
$outdate = $oDate;
}
$bsql = mysql_query("select * from dtr where Exception = 'Out' And Time Between
'$checktime' and '$outtime'")or die(mysql_error());
while($brow = mysql_fetch_array($bsql)){
$bID = $brow['ACNo'];
$bDate = $brow['Date'];
$bTime = $brow['Time'];
$bState = $brow['State'];
echo $bDate.' - ';
echo $bTime.' ';
echo $bState.'<br>';
}
}
}
?>
编辑:根据要求..我一直期待或想要的输出是这样的......
5/13/2013 | 11:45:18 PM | Check In
5/14/2013 | 12:46:58 AM | Out
5/14/2013 | 12:52:41 AM | Out Back
5/14/2013 | 02:12:50 AM | Out
5/14/2013 | 02:43:11 AM | Out Back
5/14/2013 | 05:46:58 AM | Out
5/14/2013 | 06:22:41 AM | Out Back
5/14/2013 | 06:55:12 AM | Check Out
Break Count : 3
Total Mins Of Break: [total here]
5/14/2013 | 11:47:13 PM | Check In
5/15/2013 | 12:36:28 AM | Out
5/15/2013 | 12:59:11 AM | Out Back
5/15/2013 | 03:12:54 AM | Out
5/15/2013 | 03:33:31 AM | Out Back
5/15/2013 | 06:55:12 AM | Check Out
Break Count : 2
Total Mins Of Break: [total here]