gpt4 book ai didi

php - 考勤、存储记录

转载 作者:行者123 更新时间:2023-11-29 23:02:26 28 4
gpt4 key购买 nike

我正在为员工建立一个时间登记系统。我开始将时间保存为 mysql 中的“Datetime”。问题是,当我有两列日期时间时,注册时间只会填充一列,第二列(取决于登录或退出)设置为“0000-00-00 00:00:00”。现在,当我想回显包含时间记录的表格时,我也会回显“空”字段。我尝试使用 if 语句,但是我的表工作得不太好,而且我不能只在“选择”中使用“订单”。有没有更好的方法来存储时间记录,或者我应该使用 php 脚本进行一些过滤?

php

<table>
<?php
//Loop out the result
while ($row = $stmt->fetch()) {
echo "<tr>";
echo "<td>" .$row['usr_stamp_in']."</td>";
echo "<td>" .$row['usr_stamp_out']."</td>";
echo "</tr>";
}
?>
</table>

最佳答案

为了使表格正确显示,您需要在任一情况下输出 。因此,请使用 if 设置一个输出字符串,该字符串可能为空,例如。

while ($row = $stmt->fetch()) {
echo "<tr>";
if($row['usr_stamp_in'] == "0000-00-00 00:00:00") {
$usr_stamp_in_display = '';
} else {
$usr_stamp_in_display = $row['usr_stamp_in'];
}
if($row['usr_stamp_out'] == "0000-00-00 00:00:00") {
$usr_stamp_out_display = '';
} else {
$usr_stamp_out_display = $row['usr_stamp_out'];
}

echo "<td>$usr_stamp_in_display</td>";
echo "<td>$usr_stamp_out_display</td>";
echo "</tr>";
}

或更短:

 while ($row = $stmt->fetch()) {
echo "<tr>";
$usr_stamp_in_display = ($row['usr_stamp_in'] == "0000-00-00 00:00:00") ? '' : $row['usr_stamp_in'];
$usr_stamp_out_display = ($row['usr_stamp_out'] == "0000-00-00 00:00:00") ? '' : $row['usr_stamp_out'];

echo "<td>$usr_stamp_in_display</td>";
echo "<td>$usr_stamp_out_display</td>";
echo "</tr>";
}

关于php - 考勤、存储记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28427724/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com