开发者

How to display grid color dynamically using PHP

开发者 https://www.devze.com 2023-02-12 21:12 出处:网络
I have text boxes, and when I start searching it displays result in table. I am trying to implement a grid.

I have text boxes, and when I start searching it displays result in table.

I am trying to implement a grid.

In this grid I have two colors so 1st row blue 2nd row green then it will come continuously for nxt rows 3rd row ii have blue and the next will be green.

How can I do that开发者_开发问答 ?


BY php

  <table width="98%" border="0">
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
    <?php 
        $i=1  while....
        if($i%2==0)
        {
        $color = "color1";
        }
        else
        {
        $color = "color2";
        }
    ?>

          <tr bgcolor="<?php $color ?>">
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
       <?php   $i++; 
        } // end while  ?>
        </table>

By css

tr:nth-child(even) {background: #CCC}
tr:nth-child(odd) {background: #FFF}

i think you looking for this


Compute oddity of your row index using modulo or bitwise AND and then apply some css class if odd/even.

0

精彩评论

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