【发布时间】:2011-03-03 08:20:14
【问题描述】:
我有一个根据存储在 mysql 数据库中的内容动态生成的数据表。
这就是我的代码的样子:
<table border="1">
<tr>
<th>Name</th>
<th>Description</th>
<th>URL</th>
</tr>
<?php
$query = mysql_query("SELECT * FROM categories");
while ($row = mysql_fetch_assoc($query)) {
$catName = $row['name'];
$catDes = $row['description'];
$catUrl = $row['url'];
echo "<tr class=''>";
echo "<td>$catName</td>";
echo "<td>$catDes</td>";
echo "<td>$catUrl</td>";
echo "</tr>";
}
?>
</table>
现在,如果表格是静态的,那么我只需按重复顺序为每个交替表格行分配 2 种样式之一:
.whiteBackground { background-color: #fff; }
.grayBackground { background-color: #ccc; }
到此为止。但是由于表格行是动态生成的,我该如何实现呢?
【问题讨论】:
-
查看取模运算符 =)
标签: php