![](/img/trans.png)
[英]PHP - "if" in "while" problems to alternate html table rows colour
[英]Changing colour for alternate rows
我想通过交替的行颜色使表格更具可读性。 我已经看完其他答案,但是看不到如何将它们应用于我的代码。 我在代码的最后一部分尝试了各种切换方法,但一切都中断了。
我不能使用jquery或CSS,因为我只能访问这部分代码。
我想切换到bgcolor =“#8BC6FD”
<table cellspacing=0 cellpadding=2 border="thin">
<col width=150>
<col width=100>
<tr bgcolor="#D4E9FC" style="outline: thin solid">
<td class="viewN"><b>TYPE:- </b></td>
<td class="viewN"><b>PACKING:- </b></td>
</tr>
<?php
$dbconn = pg_connect("host=127.0.0.1 XXXX password=YYYY)") or die('Could not connect: ' . pg_last_error());
$query = "SELECT * FROM stock
ORDER BY name" ;
$result = pg_query($query);
if (!$result) {
echo "Problem with query " . $query . "<br/>";
echo pg_last_error();
exit();
}
while($myrow = pg_fetch_assoc($result)) {
printf ("<tr><td>%s</td><td>%s</td></tr>", htmlspecialchars($myrow['type']),htmlspecialchars($myrow['packing']));
}
?>
</table>
我不能使用jquery或CSS,因为我只能访问这部分代码。
目前尚不清楚您指的是代码的哪一部分。 假设您可以访问显示的所有代码,则可以将<style>
标记放在<table>
之前或之后。
就像定义第n个CSS一样简单
<style>
/* tr:nth-child(odd) {background-color: #0000cc} */
tr:nth-child(even) {background-color: #D4E9FC}
</style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.