我试图阻止下表中的数据继续重复自身,例如循环相同的数据,使浏览器崩溃:
这是查询:
$posts = mysqli_fetch_assoc(mysqli_query($db, "SELECT * from tbl_bugresponse WHERE bugid = $id ORDER BY time"));
这是表格代码:
<table width="100%" class="tborder">
<tr>
<th class="tcat">Name</th>
<th class="tcat">Reply</th>
</tr>
<?php
$colour="1";
while($posts) {
if($colour == "1"){
echo ("<tr class='alt1'>");
$f1 = $posts['by'];
$f2 = $posts['content'];
$colour = "2";
}
else {
echo "<tr class='alt2'>";
$f1 = $posts['by'];
$f2 = $posts['content'];
$colour = "1";
}
?>
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>
</tr>
<?}?>
</table>
请注意,我使用的是 mysqli 而不是 mysql。