Jump to content

Print Page and record


Ell20

Recommended Posts

Hi,

 

I have a page which users may want to print off, I want to design a link which prints the page off. In addition to this I would like to be able to store the amount of times the page was printed, or the link was clicked, is this possible as I have no idea how this can be done? I have a database so is neccessary the count can be recorded and updated in there.

 

Appreciate your help

 

Elliot

Link to comment
https://forums.phpfreaks.com/topic/109594-print-page-and-record/
Share on other sites

add this to the top:

<?php
if ($_GET['print'] == true){
//mysql update query here
$body = " onload=\"window.print();\"";
}
else{
$body = "";
}
?>

and in your page, add this to your body tag

<body<?php print $body; ?>>

then, just creat a link like this

<a href="?print=true">Print this page</a>

You can incorporate it using either get or post. Her's another basic example

 

<body>

<form name='form1' method='post' action="<?php $_SERVER[php_SELF] ?>">

<input type='hidden' name='clicked' value=""/>

</form>

 

<?php

if(isset($_POST['clicked'])){

 

//make connection to DB and add 1 to the number of times clicked

echo "link clicked";

}

else{

 

echo '<a href="#" onclick="print_page(); return false;">Print Document</a>';

}

 

?>

<script language='javascript'>

 

function print_page(){

 

window.print();

form1.clicked.value = '1';

form1.submit();

}

</script>

 

</body>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.