【发布时间】:2014-02-05 13:43:05
【问题描述】:
我想我正在尝试更改 php 表的 tr 的 bgcolor,它从循环中获取数据。在所有 php html 方面,我都是一个不错的菜鸟。一直在尝试这一天,但无法让它在查找数据时更改 bgcolor。
从 mysql 数据库获取所有数据的循环工作正常,现在我不知道如果超过 30 天并且状态为 OUT,如何进一步更改输出以更改 bgcolor。
这是我目前拥有并尝试的代码。任何帮助将不胜感激。
$con=mysqli_connect($host, $db_user, $db_pass, $db);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM data");
$sql77 = "SELECT * FROM data WHERE dt_in < date_sub(curdate(), INTERVAL 30 DAY) AND status != OUT";
$result77 = mysql_query($con,$sql77);
echo "<table border='1'>
<tr bgcolor='lightgrey'>
<th>Signed in by</th>
<th>Reference Number</th>
<th>Asset Number</th>
<th>Make Model</th>
<th>Operating System</th>
<th>Office</th>
<th>Profile</th>
<th>Extra Apps</th>
<th>Time IN</th>
<th>Status</th>
<th>Time OUT</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
if (!$result77) {
echo "<tr>";
} else {
echo "<tr bgcolor='red'>";
}
echo "<td>" . $row['who'] . "</td>";
echo "<td>" . $row['ref'] . "</td>";
echo "<td>" . $row['asset'] . "</td>";
echo "<td>" . $row['make_model'] . "</td>";
echo "<td>" . $row['os'] . "</td>";
echo "<td>" . $row['office'] . "</td>";
echo "<td>" . $row['swp'] . "</td>";
echo "<td>" . $row['ea'] . "</td>";
echo "<td>" . $row['dt_in'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "<td>" . $row['dt_out'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo $result77;
mysqli_close($con);
?>
这最终解决了我的问题。
while($row = mysqli_fetch_array($result))
{
if(time() - strtotime($row['dt_in']) > 2592000 && $row['status'] != 'OUT') //2592000 sec == 30 days
{
echo "<tr class='MyOut'>";
} else {
echo "<tr>";
}
echo "<td>" . $row['who'] . "</td>";
echo "<td>" . $row['ref'] . "</td>";
【问题讨论】:
-
所以...
$result77到底是在哪里定义的?它不在您的代码中的任何位置,因此if(!$result77)将始终为真。 -
这里没有定义 $result77:$sql77 = "SELECT * FROM data WHERE dt_in
-
html5 不支持 bgcolor 属性,在 html 4.01 中已弃用。改用 css。
-
我很抱歉。我错过了获取电话。
-
仍然不知道该怎么办,忙着用谷歌搜索并理解它。
标签: php mysql loops if-statement