Ell20 Posted June 10, 2008 Share Posted June 10, 2008 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 More sharing options...
jonsjava Posted June 10, 2008 Share Posted June 10, 2008 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 https://forums.phpfreaks.com/topic/109594-print-page-and-record/#findComment-562157 Share on other sites More sharing options...
hansford Posted June 10, 2008 Share Posted June 10, 2008 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 https://forums.phpfreaks.com/topic/109594-print-page-and-record/#findComment-562178 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.