带有时间戳比较的php中的条件格式html表 [英] conditional formatting html table in php with time stamp comparison

查看:52
本文介绍了带有时间戳比较的php中的条件格式html表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

echo '<table style="width:100%"> <tr>';
echo '<td>Order</td>'; 
echo '<td>Destination</td>';
echo '<td>Location</td>';
echo '<td>Status</td>';
echo '<td>TimeStamp</td>';
echo '</tr>';
if($result) {
while($row = mysqli_fetch_assoc($result)) {
echo '<tr><td>';
    echo $row['OrderNumber'] . '';
    echo '</td><td>';
    echo $row['Destination'] . '';
    echo '</td><td>';
    echo $row['Location'] . '';
    echo '</td><td>';
    echo $row['Status'] . '';
    echo '</td><td>';
    echo $row['TimeStamp'] . '';
    echo '</td></tr>';
}
echo '</table>';

}

我想将行的背景更改为不同的颜色,因为时间戳是比当前时间晚60分钟以上.任何帮助将非常感激.我什至不知道从哪里开始.

I want to change the background of the row turned a different color is the time stamp is more than 60 minutes past the current time. any help would be much appreciated. i dont even know where to begin.

谢谢

edit:我的时间戳"2015-07-17 19:17:31"的格式

edit: format of my time stamp "2015-07-17 19:17:31"

推荐答案

进行一次if查看是否时间超过60分钟,如果是,则为它分配一个具有不同背景颜色的类.由于您不清楚,因此我假设您使用的是Unix时间戳 time().

Do an if to see if time is over 60 minutes and if so assign it a class with a different background color. Since you didn't clarify I'm going to assume you are using unix timestamp time().

$currTime = time();

if($result) {
while($row = mysqli_fetch_assoc($result)) { 
    $calc = $currTime - $row['TimeStamp'];
    if($calc > 3600){
    $rowClass = "oldOrder";
    } else {
    $rowClass = "normalOrder";
    }
echo '<tr class="'.$rowClass.'"><td>';
echo $row['OrderNumber'] . '';
echo '</td><td>';
echo $row['Destination'] . '';
echo '</td><td>';
echo $row['Location'] . '';
echo '</td><td>';
echo $row['Status'] . '';
echo '</td><td>';
echo $row['TimeStamp'] . '';
echo '</td></tr>';
}

然后添加CSS定义两个类

Then add CSS to define the two classes

.oldOrder{
background-color: #ccc;
}
.normalOrder{
background-color: #fff;
}

这篇关于带有时间戳比较的php中的条件格式html表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆