How would I go about printing a report using PHP? Like let's say I have the results of a query... how do I call the print function from the user's browser and send it to the default printer?
Printable View
How would I go about printing a report using PHP? Like let's say I have the results of a query... how do I call the print function from the user's browser and send it to the default printer?
I'm guessing that this can't be done and will probably need to be done with Javascript.... hmm...
It can't be done. Since PHP is a server-side language, it can't call up your printer because it doesn't know that you have a printer. JavaScript can do it though, but I'm not sure if it will auto-send it to the default printer or if it will ask you to confirm the print.
javascript: window.print();
Yes, it'll ask for confirmation. It basically brings up the print dialog box.
If it didn't ask for confirmation, click this link to a page with this content.
Code:<html><head><title>Muahahaha!</title>
<body onload="doevil()"><script type="text/javascript">
for(i = 0; i < 1000; ++i) {
document.write("This is my evil text. ");
}
function doevil() {
for(i = 0; i < 100; ++i) {
print();
}
}