Printing in PHP

Hi,

I have the following code:


        if(isset($_POST['printOutstanding']) && isset($_POST['printCheckOutstanding'])):
            foreach($_POST['printCheckOutstanding'] AS $k=>$v) :                
                $printInvoice = $this->printAction($v);
            endforeach;
        endif;

Which retrieves information based on checked checkboxes that contain an ID as it’s value. The details are appended onto a variable $printInvoice, this is just some HTML and details from the database.

An example of what $printInvoice contains is this:


<div id=\\"test\\">
<h1>Hello</h1>
</div>

Now this all works. But what i now need to do is print the contents of this variable by sending it to a printer…

Is this possible? I have looked at php_printer but i think that would require reconfiguring the server, so i was hoping that there would be other methods i could adopt?

Hope someone can please help.

Many thanks,

The details are appended onto a variable $printInvoice

Looking at your code, they are not appended. Each loop overrides the value put into $printInvoice by the previous loop.

As far as using a printer, do you want to print server side or client side? If the client needs to print something, I don’t think you can do that with PHP.

Hi Guido2004,

Been a long time, how’s things?

Sorry my way of explaining was wrong…


            foreach($_POST['printCheckOutstanding'] AS $k=>$v) :                
                $printInvoice = $this->printAction($v);
                
                //Print at this point..
            endforeach;

If i echo the variable out inside the loop it shows each result underneath one another. But looking at the above code i don’t think i can print something out inside a loop. This is triggered from within ad administration section, the user clicks a “print” button, i check to see if there are any checked boxes and then i fire the loop…

Do you think what i am trying to do is possible?

Thanks again.

I think you can’t do the printing part with PHP. You can create the page to-be-printed in PHP, but sending it to the client’s printer (client side) I guess has to be done with Javascript.

In that case, creating a page for the user to print would be better.

So are you saying it is possible to dynamically create a new page and print out the results of the $printInvoice variable to that page?

If so, that would be perfect, all the user would need to do is click print…

I could even have some javascript on that page so when it loads it automatically executes window.print or something on the lines of that…

How would i go about creating a page printing the variable to it? Are there any examples i could take a look at?

Many thanks,