根据经过的时间更改单元格颜色

时间:2019-04-13 06:10:12

标签: php mysql

所以,我撞到了砖墙。我想要做的是根据经过的时间更改表中“等待”单元格的颜色。查询时,“等待”单元格以00:00:00的格式显示时间戳。为了使我的编码更加一致,并使下一个可能替换我的人更容易。我正在查询我在mysql数据库中创建的用于更新时间戳的视图。因此,我所有的html / php代码要做的就是查询视图以提取我想要显示的信息。

我搜寻了互联网,发现了几段代码,它们应该能够根据值更改单元格的颜色。我有一点运气,但没有获得理想的结果。我要么结束时保持不变的颜色并且没有更改,要么发现代码有问题,阻止了整个页面的加载。

include 'config/database.php';
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$records_per_page = 5;
$from_record_num = ($records_per_page * $page) - $records_per_page; 
$query = "SELECT ptfin, ptname, ptdob, pore, notes, labstat,
                 rtstat,radstat,waiting 
            FROM dashboard_view 
            WHERE ( labstat != '' AND labstat IS NOT NULL) 
               OR (radstat != '' AND radstat IS NOT NULL) 
               OR (rtstat != '' AND rtstat IS NOT NULL) 
            ORDER BY waiting DESC 
            LIMIT :from_record_num, :records_per_page";
$stmt = $con->prepare($query);
$stmt->bindParam(":from_record_num", $from_record_num, PDO::PARAM_INT);
$stmt->bindParam(":records_per_page", $records_per_page, PDO::PARAM_INT);
$stmt->execute();
$num = $stmt->rowCount();


$curDate = time();
$mysqlTimestamp = $row['waiting']; //This is the piece of code that is giving me issues. 
$dif = strtotime($curdate) - strtotime($mysqlTimestamp);

if($num>0) 
    if($dif < 10000) {
        $tdStyle='background-color:green;';
    } else {
        $tdStyle='background-color:red;';
    }

    echo "<table class='table table-hover table-responsive table-bordered'>";

    echo "<tr>";
        echo "<th>FIN#</th>";
        echo "<th>Name</th>";
        echo "<th>PorE</th>";
        echo "<th>Notes</th>";
        echo "<th>Modalities</th>";
        echo "<th>Waiting</th>";
    echo "</tr>";

    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){

        extract($row);
        echo "<tr>";
        echo "<td width=15>{$ptfin}</td>";
        echo "<td width=100>{$ptname}</td>";
        echo "<td width=5>{$pore}</td>";
        echo "<td width=200>{$notes}</td>";
        echo "<td width=170><img src=".$labstat." ><img src=".$rtstat." ><img src=".$radstat." ></td>";
        echo "<td style=\"$tdStyle\" width=50>{$waiting}</td>";
        //echo "<td width=5>{$dif}</td>"; code for testing visual output of timestamp mathmatics

        echo "</tr>";
    }
    echo "</table>";

我想发生的事情是,如果时间戳少于10分钟,则该单元格显示为绿色。如果时间戳落在10到15分钟的范围内,则该单元格将显示黄色。如果时间戳大于15分钟,则该单元显示为红色。

0 个答案:

没有答案