--- 表代码 --- -6ren">
gpt4 book ai didi

php - 突出显示当天从数据库中获取的表行

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

使用下面的代码,我从我的数据库中获取了一个表。第一列有一个日历,我想知道是否可以突出显示包含当天的表格行。

我也用这个脚本显示当天:

    <?php
date_default_timezone_set("Europe/Rome");
echo " Italy: " . date("h:i:sa");
echo " day " . date("d/m/Y") . "<br>";
?>

--- 表代码 ---

     <?php
$query = "SELECT * FROM trip";
$result = mysql_query($query);

echo "<table >"; // start a table tag in the HTML

while($row = mysql_fetch_array($result)){ //Creates a loop to loop through results
echo "<tr>
<td>" . $row['Day'] . "</td>
<td>" . $row['Country'] . "</td>
<td>" . $row['Place'] . "</td>
<td>" . $row['Flight'] . "</td>
</tr>"; //$row['index'] the index here is a field name
}

echo "</table>"; //Close the table in HTML
mysql_close(); //Make sure to close out the database connection

?>

---css代码--

table
{
font-family: verdana;

color: white;
background: #003366;
text-align:center;
font-size:16px;
border-collapse: collapse;

}
tr {

padding-top:5px;
padding-bottom:5px;
font-size:16px;

}

tr:hover{

color:#003366;
background: white;

}

---添加类(class).TODAY

.今天
{
字体系列:verdana;
背景:红色;
颜色:#003366;
}

最佳答案

只是改变:

echo "<tr>
<td>" . $row['Day'] . "</td>
<td>" . $row['Country'] . "</td>
<td>" . $row['Place'] . "</td>
<td>" . $row['Flight'] . "</td>
</tr>"; //$row['index'] the index here is a field name
}

与:

if ($row['Day'] ==  date("Y-m-d") ) {
echo '<tr class="today">';
} else {
echo "<tr>";
}
echo "<td>" . $row['Day'] . "</td>
<td>" . $row['Country'] . "</td>
<td>" . $row['Place'] . "</td>
<td>" . $row['Flight'] . "</td>
</tr>"; //$row['index'] the index here is a field name
}

并将类 today 添加到您的 css 文件中。

抱歉,我无法调试它,但我认为你有一个想法

关于php - 突出显示当天从数据库中获取的表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28183002/

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