I have a fairly simple query in which I'd like to alternate styling of table rows. I have some logic mixed up in the while and for loop most likely but I'm stuck on how to correct it.
<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>