想实现在网页上显示隔行换色的功能,我用的是下面的第二种方法,理论上是可以的啊,结果全是一种颜色,后来查了查,还有第一种方法,挺好用的。只是想知道第二种方法那里出了问题,很困惑,以前都行的,查了好多资料,没有详解,求高手指点……
      //方法一
      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++;
      }