开发者

Change background color for different DIV's in PHP/SQL output

I'm trying to form my PHP/MySQL output in a 'Word-like' table format: one row is background color X, the next is bg color Y, then X again, then Y, etc.

To do this I've come up with a solution, but I'm guessing it's not really the neatest or cleanest way to do it. Check out my solution. I'm looking forward to your ideas/input!

$selectdoc = "SELECT * FROM document WHERE docid = '" . $_GET['docid'] . "' LIMIT 10";
$queryselectdoc = mysql_query($selectdoc);

$colorindicator = 1;

while($dbdoc = mysql_fetch_object($queryselectdoc)) {

   $title = "$dbdoc->titl开发者_高级运维e";

   $colorindicator = $colorindicator+1;

     if ( $i&1 )
      {
        echo "<div id=\"even\">My BG color is the one based on EVEN!</div>";
      }
     else
      {
        echo "<div id=\"odd\">My BG color is the one based on ODD!</div>";
      }

 }


You can do it using CSS pseudo classes :nth-child using a list or a table or something

Try using a list like this :-)


This is shorter:

echo ((++$colorindicator % 2)==1) ? "<div id=\"odd\">" : "<div id=\"even\">";
echo "contents</div>";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜