1

Using PHP to print a variable in the footer of my HTML pages (before inserting a print page-break,) I attempted to use this solution. Essentially, I am wrapping the printed php variable in a <div> set to @media print and giving it position:fixed; bottom:0;.

However, the variable overlaps every echoed instance of itself on every page printed. Is there a way to print a dynamic variable to the footer using this method that only shows the current page's variable's value?

Example code:

    <html>
    <head>
<style type="text/css">
.break { 
    page-break-after: always;
    width:0px;
    height:0px;
}

    @media screen {
        div.divFooter {
            display: none;
        }
    }
    @media print {
        div.divFooter {
            position: fixed;
            bottom: 0;
        }
    }
    </style>
    </head>
    <body>

<?php

$footer = ''; //footer is a dynamic variable whose value is set within a loop that also sets page breaks.
echo '<div class="divFooter">'.$footer.'</div>';
echo '<div class="break"></div>';

?>
    </body>
    </html>
Community
  • 1
  • 1
Dylanotron
  • 51
  • 2
  • 7
  • You need to separate the problems a bit. First, is the `$footer` value printing correctly? Check the raw HTML in the browser to confirm that. If so, PHP is completely irrelevant here. I think you're just asking for a CSS presentation issue, which you should clarify better. What does it look like and what should it look like? – deceze Oct 23 '11 at 02:45
  • You're right, it is better to look at CSS and PHP seperately. For clarity, let's pretend the $footer variable outputs "Page xx", and increments 1 every time a page a
    is inserted. Using the solution above, the $footer output for every page is the $footer text, stacked upon itself every time the footer has been echoed. That is to say, if I am to preview 3 printed pages, every printed page's printed footer outputs "Page " + numbers 1, 2, and three stacked on top of each other.
    – Dylanotron Oct 25 '11 at 17:37

2 Answers2

1

My original question is if using CSS's position: fixed; display:none; bottom:0; for the $footer's print style is a feasible solution if $footer is dynamic page-to-page. My solution was to forgo the @media print style and just output my footer at the bottom of the generated output for every printed page, essentially:

    .footer {
        float:right;
    }

    <?php

    $page++;
    $break = 1;

    if ($break == 1){
        echo '<div class="footer">'.$footer.'</div>';
        $break = 0;
        echo '<hr class="break" />';
    }
    ?>
Dylanotron
  • 51
  • 2
  • 7
0

You could try using the $_SERVER super global to determine which "page" you are on and alter the footer based on that. Try using $_SERVER['REQUEST_URI'] .

ghbarratt
  • 11,496
  • 4
  • 41
  • 41