如何改变字体颜色,如果行显示缺席的结果


how to change font color if row show absent result

如何改变字体颜色如果行显示缺席结果然后

如果行显示不存在如何更改行的字体颜色我怎么能做到这一点,请帮助我解决这个问题,谢谢

这个代码

$result1 = mysql_query("SELECT * FROM attendance where date '2013-4-30'  order by date ASC");
            while($row = mysql_fetch_array($result1))
            {   

            // echo out the contents of each row into a table
       echo "<tr>";
            echo '<td>' . $row['teacherid'] . '</td>';
            echo '<td>' . $row['name'] . '</td>';
            echo '<td>' . $row['date'] . '</td>';
            echo '<td>' . $row['attendance'] . '</td>';
            echo "</tr>"; 

,这是代码

的结果
-------------------------------------------
Teacher Id | Name  | Date     |Attendance |
--------------------------------------------
919        | Abcd  |2013-4-30 |present
918        | xyz   |2013-4-30 |absent 
815        | 123   |2013-4-30 |present
-------------------------------------------

我想改变缺席的文本颜色

Replace

echo "<tr>";

echo '<tr class="'.$row['attendance'].'">';

然后在CSS中输入

.present { color: green; }
.absent { color: red; }

如果你只是想让考勤单元格改变颜色,你可以把课程放在<td>而不是<tr>上。

编辑:

完整版本的代码。

$result1 = mysql_query("SELECT * FROM attendance where date '2013-4-30'  order by date ASC");
        while($row = mysql_fetch_array($result1))
        {   

        // echo out the contents of each row into a table
   echo '<tr class="'.$row['attendance'].'">';
        echo '<td>' . $row['teacherid'] . '</td>';
        echo '<td>' . $row['name'] . '</td>';
        echo '<td>' . $row['date'] . '</td>';
        echo '<td>' . $row['attendance'] . '</td>';
        echo "</tr>";

如果你还没有一个样式表,那就把它放在你的页面的HTML:

<style type="text/css">
    .present { color: green; }
    .absent { color: red; }
</style>