asp中可以用mod函数,php刚学,不知道可否
变量i
为显示条数
每显示一条加一  i++if i mod 2 = 0 then
………………
else
end if

解决方案 »

  1.   

    PHP中取余为 %
    楼上的方法可行~~if i mod 2 = 0 then
    ………………
    else
    end ifif(i % 4 = 0)
    {}或者设置颜色的时候利用编号来运算~~~我们知道颜色是从#000000 - #ffffff。你可以寻找一个合适的公式来对应这个关系~~~~
      

  2.   

    $i=0;
    $c=array("#FFFFFF","#CCCCCC","#F0F0F0","#000000");
    while($array = mysql_fetch_array($result){
      echo "<td bgcolor='".$c[$i]."'>".$array[0]."</td>\n";
      echo "<td bgcolor='".$c[$i]."'>".$array[1]."</td>\n";
      $i++;
      if($i>3) $i=0;
    }
      

  3.   

    <?
    $table="shop";
    $query = "SELECT * FROM $table where hot=2 ORDER BY id DESC LIMIT 0,6";
    $result = MYSQL_QUERY($query);
    while($row=mysql_fetch_row($result))
    {
    $g_id=$row[0];
    $g_line=$row[1];
    $g_lxs=$row[2];
    //$g_hotel=$row[3];
    $g_goodprice=$row[9];
    $g_price=$row[8];
    $g_photo=$row[12];
    $route_scope=$row[3];
    $route_scope2=$row[4];
    //$g_line=substr($g_line,0,22);
    //$ttt=$PHPSESSID;
    //print "<table width=\"100%\"><tr><td><img src=image/arr1.gif>$route_scope/$route_scope2</td><td>$g_line</td><td>$g_price</td><td>$g_goodprice</td><tr></table>";
    $i=0;
    $c=array("#FFFFFF","#CCCCCC","#F0F0F0","#000000");
    print "<table width=\"100%\"><tr><td bgcolor=\".$c[$i].\"><img src=../image/arr1.gif><a href=show_shop.php?travel_id=$g_id&travel=$g_line>$g_line</a></td><td width=\"16%\"><div align=\"center\">$g_price</div></td><td width=\"20%\"><div align=\"center\">$g_goodprice</div></td><tr></table>";
    $i++;
    if($i>3) $i=0;
    }
    ?>
    不行呀
      

  4.   

    用js来做拉
    <SCRIPT LANGUAGE="JavaScript">
    window.onload = function() {
    doubleBgColor(document.getElementById("table1"),"#cecece","#ececec")
    }function doubleBgColor(Table,Bg1,Bg2) {
    for (var i=0;i<Table.rows.length;i++) Table.rows[i].bgColor=i%2?Bg2:Bg1;
    }
    </SCRIPT>
    <TABLE border=0 cellpadding=1 cellspacing=1 id="table1" width="300">
    <TR><TD>&nbsp;</TD></TR>
    <TR><TD>&nbsp;</TD></TR>
    <TR><TD>&nbsp;</TD></TR>
    <TR><TD>&nbsp;</TD></TR>
    <TR><TD>&nbsp;</TD></TR>
    <TR><TD>&nbsp;</TD></TR>
    <TR><TD>&nbsp;</TD></TR>
    <TR><TD>&nbsp;</TD></TR>
    <TR><TD>&nbsp;</TD></TR>
    <TR><TD>&nbsp;</TD></TR>
    <TR><TD>&nbsp;</TD></TR>
    <TR><TD>&nbsp;</TD></TR>
    </TABLE>
      

  5.   

    不行啊!!<SCRIPT LANGUAGE="JavaScript">
    window.onload = function() {
    doubleBgColor(document.getElementById("table1"),"#990022","#999900")
    }function doubleBgColor(Table,Bg1,Bg2) {
    for (var i=0;i<Table.rows.length;i++) Table.rows[i].bgColor=i%2?Bg2:Bg1;
    }
    </SCRIPT> 
                  <?
    $table="shop";
    $query = "SELECT * FROM $table where hot=2 ORDER BY id DESC LIMIT 0,6";
    $result = MYSQL_QUERY($query);
    while($row=mysql_fetch_row($result))
    {
    $g_id=$row[0];
    $g_line=$row[1];
    $g_lxs=$row[2];
    //$g_hotel=$row[3];
    $g_goodprice=$row[9];
    $g_price=$row[8];
    $g_photo=$row[12];
    $route_scope=$row[3];
    $route_scope2=$row[4];
    //$g_line=substr($g_line,0,22);
    //$ttt=$PHPSESSID;
    //print "<table width=\"100%\"><tr><td><img src=image/arr1.gif>$route_scope/$route_scope2</td><td>$g_line</td><td>$g_price</td><td>$g_goodprice</td><tr></table>";
    print "<table width=\"100%\" id=\"table1\" cellpadding=1 cellspacing=1><tr><td><img src=../image/arr1.gif><a href=show_shop.php?travel_id=$g_id&travel=$g_line>$g_line</a></td><td width=\"16%\"><div align=\"center\">$g_price</div></td><td width=\"20%\"><div align=\"center\">$g_goodprice</div></td><tr></table>";
    }
    ?>
      

  6.   

    晕,
    $i=0放在while里面当然不行,
    每次循环$i都被赋予0值,当然每次都取$c[0]的颜色值了.把$i=0放在while之前啊.