【发布时间】:2015-03-26 19:21:58
【问题描述】:
通过下面的代码,我正在从我的数据库中获取一个表。第一列有一个日历,我想知道是否可以突出显示包含当天的表格行。
我也用这个脚本显示当前日期:
<?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;
}
---添加类 .TODAY
.today
{
font-family: verdana;
background: red;
color: #003366;
}
【问题讨论】:
-
将 CSS 类添加到行。
-
$row['Day']的格式化输出是什么? -
我的 css 上有这个,因为背景是蓝色的,所以它以白色突出显示该行,但是如何根据当天自动突出显示该行?
-
您需要使用条件语句并检查该行是否等于所述日期。
-
@gigi 如果你回答了上面的问题会很有帮助。
标签: php mysql html-table