/    Sign up×
Community /Pin to ProfileBookmark

Alternate row color ?

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 :

[code=php]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;

}[/code]

How can I make $lines have alternate row color ?

Thanks !

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@artemisNov 17.2008 — [code=php]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'.(($c++)%2?' colour_class':'').'">';
$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;

} [/code]


Put the class in your stylesheet and set whatever colour you want
Copy linkTweet thisAlerts:
@PeuplarchieauthorNov 17.2008 — There we are !

[code=php]
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'.(($c++)%2?' colour_class':'').'">';
$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);
$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;

}

[/code]
×

Success!

Help @Peuplarchie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...