【发布时间】:2018-12-02 17:49:56
【问题描述】:
我正在使用 mysql 查询从数据库中获取数据。我所有的数据在表格中都显示得很好。现在我想按小于 2 或大于 3 的值对状态进行着色。 下面的代码不起作用。 需要帮助。
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
$output .= '<div class="table-responsive">
<table class="table table bordered">
<tr>
<th>name</th>
<th>genre</th>
<th>time</th>
<th>status</th>
<th>more...</th>
</tr>';
?>
<?php
function status_style($row) {
if ($row < 2) return 'background-color: #ff0000'; //red
if ($row > 3) return 'background-color: #33cc33'; //green
return '';
}
?>
<?php
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["name"].'</td>
<td>'.$row["genre"].'</td>
<td>'.$row["time"].'</td>
<td>'.$row["status"].'</td>
<td>'.$row["more"].'</td>
</tr>
';
}
echo $output;
{
echo 'Data Not Found';
}
?>
【问题讨论】:
标签: php css mysqli colors html-table