Jump to content

Alternate row color ?


Peuplarchie

Recommended Posts

Good day to you all,

            Here I come again with a piece of code which reach a txt file and return the text, it also convert the "\n" into "<br>".

 

Here it is :

 

function drawList($list)
{     
      $thelist = '';         
      foreach($list as $file=>$string)
      {

        $lines = nl2br($string);
              $thelist .= '<b class="b1h"></b><b class="b2h"></b><b class="b3h"></b><b class="b4h"></b>';
              $thelist .= '<div class="headh">';
              $thelist .= '<b>'.$file.'</b>';
              $thelist .= '</div>';              
              $thelist .= '<div class="contenth"><div class="text">';
              $thelist .= $lines.'<br/>';
              $thelist .= '</div>';
              $thelist .= '</div>';
              $thelist .= '<b class="b4bh"></b><b class="b3bh"></b><b class="b2bh"></b><b class="b1h"></b><br/>';
    }
    return $thelist;
        
}

 

 

How can I make $lines have alternate row color ?

 

Thanks !

Link to comment
https://forums.phpfreaks.com/topic/133029-alternate-row-color/
Share on other sites

function drawList($list)
{     
$color1 = "#cccccc";
$color2 = "#ffffff";
$color = $color1;

      $thelist = '';         
      foreach($list as $file=>$string)
      {

        $lines = nl2br($string);
              $thelist .= '<b class="b1h"></b><b class="b2h"></b><b class="b3h"></b><b class="b4h"></b>';
              $thelist .= '<div class="headh">';
              $thelist .= '<b>'.$file.'</b>';
              $thelist .= '</div>';              
              $thelist .= '<div class="contenth" style="background-color:'.$color.'"><div class="text">';
              $thelist .= $lines.'<br/>';
              $thelist .= '</div>';
              $thelist .= '</div>';
              $thelist .= '<b class="b4bh"></b><b class="b3bh"></b><b class="b2bh"></b><b class="b1h"></b><br/>';
$color = ($color == $color1 ? $color2 : $color1);
    }
    return $thelist;
        
}

 

Try that out.

Link to comment
https://forums.phpfreaks.com/topic/133029-alternate-row-color/#findComment-691901
Share on other sites

Than ya wud want replace nl2br to maybe something like

 
$lines=explode("\n",$lines);
$count=0;
$color[0] = "#cccccc";
$color[1] = "#ffffff";
foreach($lines as $key=>$line)
{  $lines[$key]="<div class=\"contentalt\" style=\"background-color:{$color[$count]}\">{$line}</div>"; $count=(++$count & 1); }
$lines=implode('<br>',$lines)

Link to comment
https://forums.phpfreaks.com/topic/133029-alternate-row-color/#findComment-692077
Share on other sites

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.