for ($i=0;$i<20;$i++)
    print ($i % 2) ? "深色" : "浅色";

解决方案 »

  1.   

    static $flag=0;if($flag==0)
       {echo "<img src=\"red.gif\">";$flag=1;}
    else if($flag==1)
       {echo "<img src=\"blue.gif\">";$flag=0;}
      

  2.   

    <?
    $arr=array('a','b','c','d','e','f');
    echo "<table border=1 width=200>";
    for($n=0;$n<count($arr);$n++){
    if($n%2){
    echo "<tr style='background:#ff0000;'><td>".$arr[$n]."</td></tr>";
    }else{
    echo "<tr style='background:#00ff00;'><td>".$arr[$n]."</td></tr>";
    }
    }
    echo "</table>";
    ?>
      

  3.   

    看看我的:)
    <table width="90%" border="0" bordercolor="#99CCFF">
    <?
    //display the news titles and others
      $rdc = true;
      while($aRow = mssql_fetch_array($r)){
        if($idc){$rowColor = $color1;}
          else $rowColor = $color2;
        $idc=!$idc;
    ?>
                                            <tr bgcolor = "<?=$rowColor?>"">
                 <td width="65%" height="30">
    <?
        echo "<a href = './news/" . $aRow["news_id"] . ".php" . "' class = 'newslist'>" . $aRow["title"] . "</a>";
    ?>
                 </td>
                 <td width="14%" height="30" align="center">
    <?
                    echo $aRow["author_name"];
    ?>
                 </td>
                 <td width="13%" height="30" align="center">
    <?
                    echo $aRow["times"];
    ?>
                 </td>
                 <td width="8%" height="30" align="center">
    <?
                    echo "<a href = delet.php?id=" . $aRow["news_id"] . "><font color = '#ff0000'>删  除</font></a>";
    ?>
                 </td>
                 </tr>
    <?
      }//end the "while" loop
    ?>
    </table>
      

  4.   

    看看我的:)
    <table width="90%" border="0" bordercolor="#99CCFF">
    <?
    //display the news titles and others
      $rdc = true;
      while($aRow = mssql_fetch_array($r)){
        if($idc){$rowColor = $color1;}
          else $rowColor = $color2;
        $idc=!$idc;
    ?>
                                            <tr bgcolor = "<?=$rowColor?>"">
                 <td width="65%" height="30">
    <?
        echo "<a href = './news/" . $aRow["news_id"] . ".php" . "' class = 'newslist'>" . $aRow["title"] . "</a>";
    ?>
                 </td>
                 <td width="14%" height="30" align="center">
    <?
                    echo $aRow["author_name"];
    ?>
                 </td>
                 <td width="13%" height="30" align="center">
    <?
                    echo $aRow["times"];
    ?>
                 </td>
                 <td width="8%" height="30" align="center">
    <?
                    echo "<a href = delet.php?id=" . $aRow["news_id"] . "><font color = '#ff0000'>删  除</font></a>";
    ?>
                 </td>
                 </tr>
    <?
      }//end the "while" loop
    ?>
    </table>