Jump to content

[SOLVED] 2 color rows when list


web_master

Recommended Posts

sure you can. Use a variable, $x.

 

<?php
//All of your code here except the while
$x = 0;

while (//Stuff Here)
{
     //More of your code here
     echo "<tr class=\"row" . $x . "\"><td>$content</td></tr>";
     if ($x == 0)
     $x++;
     else
     $x--;
}
?>

Then you need two styles, one for tr.row0 and one for tr.row1

if you're creating the list in a foreach, while or for statement it's quite easy. Before the statement set a variable to 1, then each loop through the statement change the digit to 2, or if it's already 2, back to 1 again.

Then set up two css classes, called something like 'line1' and 'line2'. You can then call up the class in php.

<?php
$i = 1
foreach($var as $k => $v){
      echo '<td class="line' . $i . '">some txt</td>';
            if($i = 1){
                  $i = 2;
            }else{
                  $i = 1;
            }
}

 

 

EDIT: beaten to it :P

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.