darga333 Posted May 8, 2006 Share Posted May 8, 2006 How do you make the window close immediately after you click "Print" but still allow it to print the page that the "Print" button was on and also allow it to update the database with print = 1.The order of operations would be:1. Click Print2. Run SQL Query$sql = "UPDATE print SET print=1 WHERE user_id='$user_id'";$result = mysql_query($sql);3. Print Dialog Pop Up4. Immediately close windowDoes anyone know how to do this? Quote Link to comment Share on other sites More sharing options...
zq29 Posted May 8, 2006 Share Posted May 8, 2006 You won't be doing that with just PHP, I can tell you that much. You'll need to use a client side language to do the closing of the window - JavaScript? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 8, 2006 Share Posted May 8, 2006 You can use Javascript for that:[code]window.close[/code]You won't be able to do this in PHP, only javascript. Quote Link to comment Share on other sites More sharing options...
darga333 Posted May 8, 2006 Author Share Posted May 8, 2006 would I close the window as soon as the print dialog pops up? the part about this whole thing that i dont understand is that the print button has to be attached to an onClickbut in that onclick it is ganna be javascript.. how can i go from javascript to php to update the database?bcause javascript is client side and php is server side.. so when they click print do i have to have it submit to the same page first, then inside of the code... if it has been submitted, then do the php first.. and then call the javascript to popup the print window and close the window in that order? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 8, 2006 Share Posted May 8, 2006 You'll want to use ajax then. That way you can interact with PHP and Javascript simultaneously. Quote Link to comment Share on other sites More sharing options...
lead2gold Posted May 8, 2006 Share Posted May 8, 2006 [!--quoteo(post=372216:date=May 8 2006, 02:46 AM:name=darga333)--][div class=\'quotetop\']QUOTE(darga333 @ May 8 2006, 02:46 AM) [snapback]372216[/snapback][/div][div class=\'quotemain\'][!--quotec--]How do you make the window close immediately after you click "Print" but still allow it to print the page that the "Print" button was on and also allow it to update the database with print = 1.The order of operations would be:1. Click Print2. Run SQL Query$sql = "UPDATE print SET print=1 WHERE user_id='$user_id'";$result = mysql_query($sql);3. Print Dialog Pop Up4. Immediately close windowDoes anyone know how to do this?[/quote]the window you pop up.... could it not have a form on it?[code]// assume this is print.php$go_print = (isset($_POST['go_print']))?true:false;<?phpif($go_print){ // execute sql statement here}?><html><head><title>print and update db</title></head><body <? ($go_print)?"onload=\"window.close();\"":""; ?>><form name="print" action="print.php"><b>Press Print:</b><input type="hidden" name="go_print" value=""><input type="submit" name="print"></form></body></html>[/code]I mean.. correct my syntactical errors i made above (as it's not tested). But the logic is basically there... Quote Link to comment Share on other sites More sharing options...
darga333 Posted May 8, 2006 Author Share Posted May 8, 2006 yeah how it works is a "Print" link will be displayed.. that print link will make the print.php page pop upit will pass a variable print = 1then i will run the SQL statement and update the databasethen it will pop up the print dialog boxand then it will immediately close the window..The question: Once the print dialog box pops up does it automatically know to print what was on the page that the Print button was on (print.php) even if i close the window before the person clicks to actually print the document?? or do you have to have the window open, and then the person prints it and only after it is printed, then you can close the window? I need to make sure that the person is actually going to print what was on the print.php page. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.