Reply to Re: print table with background colors

Your name:

Reply:


Posted by Bob Bedford on 12/15/05 12:01

"Ian B" <ianbambury@gmail.com> a écrit dans le message de news:
1134594287.504278.214300@g49g2000cwa.googlegroups.com...
> What happened there?
> Should have read:
>
>
> ZeldorBlat wrote:
>> Try an HTML or CSS newsgroup.
>
> Why? It's a programming problem.
>
> Try this:
>
>
> <html>
> <head>
> <title></title>
> <style>
>
> td
> {
> border : solid 1px blue;
> }
> .oddrow
> {
> background-color : #FFFFFF;
> }
> .evenrow
> {
> background-color : #CCCCCC;
> }
> #table1
> {
> border : solid 1px black;
> }
> </style>
> </head>
> <body>
> <?php
>
> $data = "Example of how to colour alternate lines";
> $data .= "<table id='table1'>";
> $colour = 0;
>
> for($i=1;$i<26;$i++)
> {
> $colour = -$colour - 1;
> $data .= ($colour)?'<tr class="oddrow">':'<tr class="evenrow">';
> $data .= "<td>&nbsp; Line $i &nbsp;</td>";
> $data .= "<td>&nbsp; Colour $colour &nbsp;</td>";
> $data .= '</tr>';
> }
> $data .= "</table>";
>
> echo $data;
> ?>
> </body>
> </html>
In fact even you example doesn't print grey lines. Try to make a preview and
look what I mean.

> for($i=1;$i<26;$i++)
> {
> $colour = -$colour - 1;
> $data .= ($colour)?'<tr class="oddrow">':'<tr class="evenrow">';
I've an other function, probably quicker ? (I hope)

for($line=1;$line<26;$line++)
echo '<td valign="top" nowrap class="'.((($line%2) ==
0)?"oddrow":"evenrow").'">'

And yes, it's probably more a question for CSS or HTML group than PHP.

Thanks for your tip.

Bob

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация