隔行换色的老问题?
想实现在网页上显示隔行换色的功能,我用的是下面的第二种方法,理论上是可以的啊,结果全是一种颜色,后来查了查,还有第一种方法,挺好用的。只是想知道第二种方法那里出了问题,很困惑,以前都行的,查了好多资料,没有详解,求高手指点……
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
//方法一
while($result=mysql_fetch_array($query)){
$bgcolor=($bgcolor=="blue") ? "white" : "blue";
echo "<tr bgcolor={$bgcolor}>";
echo "<td><a href=detail.php?gid={$result['gid']}>{$result['gname']}</a></td>";
echo "<td>{$result['endtime']}</td>";
echo "<td>{$result['current_price']}</td>";
echo "<td>{$result['reply_num']}</td>";
echo "</tr>";
}
//方法二
$flag=1;
while($result=mysql_fetch_array($query)){
if($flag % 2 == 0) $bgcolor="yellow";else $bgbolor="white"; //这种方式理论上可以阿
echo "<tr bgcolor={$bgcolor}>";
echo "<td><a href=detail.php?gid={$result['gid']}>{$result['gname']}</a></td>";
echo "<td>{$result['endtime']}</td>";
echo "<td>{$result['current_price']}</td>";
echo "<td>{$result['reply_num']}</td>";
echo "</tr>";
$flag++;
}
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号