Home > Backend Development > PHP Tutorial > 隔行换色的老有关问题

隔行换色的老有关问题

WBOY
Release: 2016-06-13 13:14:25
Original
878 people have browsed it

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

PHP code
<!--

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=%7B%24result%5B'gid'%5D%7D">{$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=%7B%24result%5B'gid'%5D%7D">{$result['gname']}</a></td>";
    echo "<td>{$result['endtime']}</td>";
    echo "<td>{$result['current_price']}</td>";
    echo "<td>{$result['reply_num']}</td>";
    echo "</tr>";
    $flag++;
      }

Copy after login


------解决方案--------------------
为毛不用jquery在前端做??代码取余效率是个问题
------解决方案--------------------
if($flag % 2 == 0) $bgcolor="yellow";else $bgbolor="white";

$bgcolor !!!

自己写错了,怪谁呢?
------解决方案--------------------
楼主先输出$flag % 2
echo $flag % 2;echo '
';
看看是不是x0x0x0x0x0的格式。如果是的。在看是不是css样式问题
style="background:颜色"
------解决方案--------------------
探讨
if($flag % 2 == 0) $bgcolor="yellow";else $bgbolor="white";

$bgcolor !!!

自己写错了,怪谁呢?
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template