【发布时间】:2016-03-07 18:29:56
【问题描述】:
当我从数据库中读取表格的内容时,如何突出显示以这种方式打印的表格行的背景颜色?有时两排。要突出显示的条件是第 3 列的值。
<?php
echo "<table id='allocation' class='inlineTable'>"; //style='border: solid 1px black;'
echo "<tr>";
echo "<th class=\"row-1 a_user\">User </th>";
echo "<th class=\"row-2 a_destination\">User </th>";
echo "<th class=\"row-3 a_tremaining\">Time Remaining </th>";
echo "<col = width: 3em />";
echo "</tr>";
echo "<col = width: 3em />";
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td style='width: 100px; border: 1px solid black;'>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "\n";
}
}
$servername = "localhost";
$dbname = "mydb";
$user = 'root';
$port = 3306;
try{
$conn = new PDO("mysql:host=$servername;port=$port;dbname=$dbname", $user);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql_fetch = $conn->prepare("SELECT user_ID, destination, trem FROM reservation_table");
$sql_fetch->execute();
$result = $sql_fetch->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows2(new RecursiveArrayIterator($sql_fetch->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
echo "</table>";
$conn = null;
?>
我可以请你帮忙吗?当trem(第三列)中的值达到 00:00 时,我想突出显示或闪烁该行。我现在的 CSS 非常基本/简单:https://jsfiddle.net/8Lfj3h0j/
真的需要帮助。
【问题讨论】: