print table with background colors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Bedford

    print table with background colors

    I've a table in wich I've this CSS:

    ..oddrow{backgr ound-color:#FFFFFF}
    ..evenrow{backg round-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

    #2
    Re: print table with background colors

    Try an HTML or CSS newsgroup.

    Comment

    • Sjoerd

      #3
      Re: print table with background colors

      Try explaining your problem more clearly.

      Comment

      • Ian B

        #4
        Re: print table with background colors


        ZeldorBlat wrote:[color=blue]
        > Try an HTML or CSS newsgroup.<html >[/color]
        <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>

        Comment

        • Ian B

          #5
          Re: print table with background colors

          What happened there?
          Should have read:


          ZeldorBlat wrote:[color=blue]
          > Try an HTML or CSS newsgroup.[/color]

          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>

          Comment

          • Bob Bedford

            #6
            Re: print table with background colors

            "Ian B" <ianbambury@gma il.com> a écrit dans le message de news:
            1134594287.5042 78.214300@g49g2 00...legr oups.com...[color=blue]
            > What happened there?
            > Should have read:
            >
            >
            > ZeldorBlat wrote:[color=green]
            >> Try an HTML or CSS newsgroup.[/color]
            >
            > 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>[/color]
            In fact even you example doesn't print grey lines. Try to make a preview and
            look what I mean.
            [color=blue]
            > for($i=1;$i<26; $i++)
            > {
            > $colour = -$colour - 1;
            > $data .= ($colour)?'<tr class="oddrow"> ':'<tr class="evenrow" >';[/color]
            I've an other function, probably quicker ? (I hope)

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

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

            Thanks for your tip.

            Bob


            Comment

            • Ian B

              #7
              Re: print table with background colors


              Bob Bedford wrote:[color=blue]
              > In fact even you example doesn't print grey lines. Try to make a preview and
              > look what I mean.[/color]

              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

              Comment

              • Ian B

                #8
                Re: print table with background colors


                Bob Bedford wrote:[color=blue]
                > I've an other function, probably quicker ? (I hope)
                >
                > for($line=1;$li ne<26;$line++)
                > echo '<td valign="top" nowrap class="'.((($li ne%2) ==
                > 0)?"oddrow":"ev enrow").'">'[/color]

                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

                Comment

                • william.clarke@gmail.com

                  #9
                  Re: print table with background colors

                  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:


                  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.

                  Comment

                  • Bob Bedford

                    #10
                    Re: print table with background colors

                    "Ian B" <ianbambury@gma il.com> a écrit dans le message de news:
                    1134644795.9703 86.87670@f14g20 00...legro ups.com...[color=blue]
                    >
                    > Bob Bedford wrote:[color=green]
                    >> I've an other function, probably quicker ? (I hope)
                    >>
                    >> for($line=1;$li ne<26;$line++)
                    >> echo '<td valign="top" nowrap class="'.((($li ne%2) ==
                    >> 0)?"oddrow":"ev enrow").'">'[/color]
                    >
                    > 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 ).'">';[/color]

                    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


                    Comment

                    • Ian B

                      #11
                      Re: print table with background colors

                      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

                      Comment

                      Working...