| Author |
print table with background colors
|
|
| Bob Bedford 2005-12-14, 6:59 pm |
| I've a table in wich I've this CSS:
..oddrow{background-color:#FFFFFF}
..evenrow{background-color:#CCCCCC}
The oddrows are white and the even are grey.
BUT ! when I do print the table, there is nothing !!!
How to print such lines colors ? the main purpose of this table is to be
printed.
Please help !
Bob
| |
| ZeldorBlat 2005-12-14, 6:59 pm |
| Try an HTML or CSS newsgroup.
| |
| Sjoerd 2005-12-14, 6:59 pm |
| Try explaining your problem more clearly.
| |
| Krustov 2005-12-14, 6:59 pm |
| <comp.lang.php , Sjoerd , sjoerder@gmail.com>
<1134589311.128412.122240@o13g2000cwo.googlegroups.com>
<14 Dec 2005 11:41:51 -0800>
> Try explaining your problem more clearly.
>
But wouldnt spoil the puzzle element fun of trying to work it out :-)
| |
|
|
ZeldorBlat wrote:
> Try an HTML or CSS newsgroup.<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> Line $i </td>";
$data .= "<td> Colour $colour </td>";
$data .= '</tr>';
}
$data .= "</table>";
echo $data;
?>
</body>
</html>
| |
|
| 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> Line $i </td>";
$data .= "<td> Colour $colour </td>";
$data .= '</tr>';
}
$data .= "</table>";
echo $data;
?>
</body>
</html>
| |
| Bob Bedford 2005-12-15, 7:55 am |
| "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:
>
> 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> Line $i </td>";
> $data .= "<td> Colour $colour </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
| |
|
|
Bob Bedford wrote:
> In fact even you example doesn't print grey lines. Try to make a preview and
> look what I mean.
Worked when I tried it - still does, actually, just tried it - IE,
Mozilla, FireFox, Opera and Avant, on a windows/Abyss server and on
Linux/Apache - all work. Of course, it doesn't print background colours
if you have background colours turned off in, say, IE | Tools |
Internet Options - but you would have checked that, right? ;-)
try http://examples.roughian.com/altlines.php
Ian
| |
|
|
Bob Bedford wrote:
> 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").'">'
OK, a challenge! If you're going for short code as opposed to
readability,
change oddrow/evenrow to c1 and c2 and use
'<tr class="c'.($i%2).'">';
Ian
| |
| william.clarke@gmail.com 2005-12-15, 6:57 pm |
| It's a browser printing setting issue, not a php or HTML issue. I
believe most browsers default to not printing background colours.
Check out this article:
http://nemesis.lonestar.org/site/color_tips.html
It covers most browsers including Safari, Netscape, IE and Mozilla
eg.
Setting Changes for Netscape Navigator 6.x - All Platforms
Under the Edit button, select Preferences. Then click on Appearance so
that it expands/explodes, and then click on Colors.
On the Colors panel, locate the section labeled "Sometimes a document
will provide its own colors and background." Make sure that "Always use
the colors and background specified by the web page" is checked. Then
press Ok.
| |
| Bob Bedford 2005-12-16, 7:56 am |
| "Ian B" <ianbambury@gmail.com> a écrit dans le message de news:
1134644795.970386.87670@f14g2000cwb.googlegroups.com...
>
> Bob Bedford wrote:
>
> OK, a challenge! If you're going for short code as opposed to
> readability,
>
> change oddrow/evenrow to c1 and c2 and use
>
> '<tr class="c'.($i%2).'">';
Great, I didn't think about such code ! this also save a test !
I like to save time in my script, and you just helped me. Thanks
Bob
| |
|
| I would suggest, however, that you go for readability over compactness.
Anything which makes code easier to maintain is good. You can come back
to one of your own, quite simple programs after six months and not even
recognise it.
With HD size and cost being what it is, file size is not an issue, nor
is memory, and nor is processor time, so there is no excuse for
unreadable code any more.
Ian
|
|
|
|