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
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>

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.