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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.