我有一个相当简单的查询,我想在其中替换表行的样式。在while和for循环中,我很可能混淆了一些逻辑,但是我仍在纠结中。
<table>
<tr>
<th>Title</th>
<th>Author</th>
<th>Media Type</th>
</tr>
<?php
if($result = $link->query("SELECT * FROM smallgroup order by Author")){
if($result->num_rows) {
while($row = $result->fetch_object()){
for($i=0;$i<10;$i++){
if($i % 2)
{
?>
<tr style="background-color:#ccc;">
<?php
}else{
?>
<tr style="background-color:red;">
<?php
}
}
?>
<td>
<?php echo $row->Title;?>
</td>
<td>
<?php echo $row->Author;?>
</td>
<td>
<?php echo $row->Media; ?>
</td>
</tr>
<?php
}
}
}
?>
</table>
最简单的方法是使用even
和odd
你的情况CSS属性
tr:nth-child(even) {background: #CCC;}
tr:nth-child(odd) {background: red;}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句