By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,569 Members | 1,422 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,569 IT Pros & Developers. It's quick & easy.

print table with background colors

P: n/a
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
Dec 14 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Try an HTML or CSS newsgroup.

Dec 14 '05 #2

P: n/a
Try explaining your problem more clearly.

Dec 14 '05 #3

P: n/a

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>&nbsp; Line $i &nbsp;</td>";
$data .= "<td>&nbsp; Colour $colour &nbsp;</td>";
$data .= '</tr>';
}
$data .= "</table>";

echo $data;
?>
</body>
</html>

Dec 14 '05 #4

P: n/a
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>

Dec 14 '05 #5

P: n/a
"Ian B" <ia********@gmail.com> a écrit dans le message de news:
11**********************@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
Dec 15 '05 #6

P: n/a

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

Dec 15 '05 #7

P: n/a

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

Dec 15 '05 #8

P: n/a
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.

Dec 15 '05 #9

P: n/a
"Ian B" <ia********@gmail.com> a écrit dans le message de news:
11*********************@f14g2000cwb.googlegroups.c om...

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).'">';


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
Dec 16 '05 #10

P: n/a
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

Dec 16 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.