maideen Posted June 15, 2013 Share Posted June 15, 2013 hi. i have a problem in printing the report to printer. Now i can print the php reports, but it will open both printer dialog and page together. But I need only one to printer dialog box. Pls help meBelow code i working fine. But only in print the reports i have issue Below my code Connection database <?php try { $hostname = "sqlserver2005"; //host $dbname = "dbdata"; //db name $username = "sa"; // username like 'sa' $pw = "pass5"; // password for the user $dbh = new PDO ("mssql:host=$hostname;dbname=$dbname","$username","$pw"); } catch (PDOException $e) { echo "cannot find the server. pls check your administrator " . $e->getMessage() . "\n"; file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND); exit; } ?> Index file <?php include_once '../inc/connection.inc.php'; ?> <?php try { $stmt = $dbh->prepare('SELECT * FROM StudentRecord order by Name'); $stmt->execute(); } catch (PDOException $e) { $output = 'Error fetching authors from database!'; include '../errormsg.php'; exit(); } foreach ($stmt as $row) { $sid[] = array('SID' => $row['SID'], 'Name' => $row['Name']); } include 'searchform.html.php'; ?> searchform.html.php <?php include '../templete/header.php'; ?> <Script Language="javascript"> function change_action() { var frm_obj=document.getElementById("frm"); frm_obj.action="data.php"; } </Script> <script language="javascript" type="text/javascript"> </script> <table class="tbl_table" align="center"> <form action="" method="POST" id="frm" > <tr> <td class="td_title" colspan="2"><strong>Help Printing</strong></td> </tr> <tr> <td class="td_class_right">Student Name</td> <td> <select name="sid" id="sid"><option value="">Student ID</option> <?php foreach ($sid as $sids): ?> <option value="<?php htmlout($sids['SID']); ?>"> <?php htmlout($sids['Name']);?> <?php htmlout($sids['SID']);?> </option> <?php endforeach; ?> </select> </td> <tr> <td class="td_button" colspan="2"> <input class="buttondesign" type="submit" value="Search" name="search" onclick="change_action()"> <input class="buttondesign" type="submit" value="print" name="print" onclick="change_action()"> </td> </tr> </form> </table> data.php <?php include_once '../inc/connection.inc.php'; ?> <?php if (isset($_POST['search']) && $_POST['search'] != "" ) { $sid = $_POST["sid"]; $stmt = $dbh->query("SELECT * FROM vwStatementOpen WHERE SID='$sid' ORDER BY RCDate"); $stmt->setFetchMode(PDO::FETCH_ASSOC); include 'view.html.php'; } ?> <?php if (isset($_POST['print']) && $_POST['print'] != "" ) { $sid = $_POST["sid"]; $stmt = $dbh->query("SELECT * FROM vwStatementOpen WHERE SID='$sid' ORDER BY RCDate"); $stmt->setFetchMode(PDO::FETCH_ASSOC); include 'print.html.php'; } ?> view.htm.php <?php include '../templete/header.php'; $total=0; $scoursefee = 0; $sinipay = 0; $sdisc = 0; $scholar = 0; $nomonth = 0; $totalpaid=0; $balance=0; $totalother=0; $totaloverall=0; ?> <?php $sid = $_POST["sid"]; $s = $dbh->query("SELECT * FROM StudentRecord WHERE SID='$sid'"); $s->execute(); while($row = $s->fetch()) { $ssid = $row['SID']; $sname = $row['Name']; $snric = $row['NRIC']; $scoursecode = $row['CourseCode']; $spaytype = $row['PayMode']; $scoursefee = $row['CourseFee']; $sinipay = $row['IniPayment']; $sdisc = $row['Discount']; $scholar = $row['ScholarShip']; $nomonth = $row['NoMonths']; } $a = $dbh->query("SELECT SUM(Amount) as Amount FROM vwStatement WHERE SID='$sid'"); $a->execute(); while($row = $a->fetch()) { $totalpaid=$row['Amount']; } $balance=$scoursefee-$totalpaid; $b = $dbh->query("SELECT SUM(Amount) as Amount FROM vwStatementopen WHERE SID='$sid'"); $b->execute(); while($row = $b->fetch()) { $totaloverall=$row['Amount']; } $totalother=$totaloverall-$totalpaid ?> <div class="title">Statement</div> <hr /> <table align="center" cellpadding="1" cellspacing="1" style="width: 100%" > <tr> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Student ID</td> <td class="labeldesign_statement" style="width: 34px">:</td> <td class="labeldesign_statement"><?php echo htmlout($ssid);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Course Fee</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($scoursefee,2);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Total Paid(Fee)</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($totalpaid,2);?></td> </tr> <tr> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Student Name</td> <td class="labeldesign_statement" style="width: 34px">:</td> <td class="labeldesign_statement"><?php echo htmlout($sname);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Initial Payment</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($sinipay,2);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Balance(Fee)</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($balance,2);?></td> </tr> <tr> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">NRIC/PP</td> <td class="labeldesign_statement" style="width: 34px">:</td> <td class="labeldesign_statement"><?php echo htmlout($snric);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Discount</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($sdisc,2);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Total Paid(Others)</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($totalother,2);?></td> </tr> <tr> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Course</td> <td class="labeldesign_statement" style="width: 34px">:</td> <td class="labeldesign_statement"><?php echo htmlout($scoursecode);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Scholarship</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($scholar,2);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Total Paid(Overall)</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($totaloverall,2);?></td> </tr> <tr> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Pay Type</td> <td class="labeldesign_statement" style="width: 34px">:</td> <td class="labeldesign_statement"><?php echo htmlout($spaytype);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">No of Month</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($nomonth);?></td> </tr> </table> <table width="100%" align="center" cellpadding="4" cellspacing="1"> <tr> <td class="tdempty"></td> <td class="tbl_header">Receipt No</td> <td class="tbl_header">Receipt Date</td> <td class="tbl_header">Description</td> <td class="tbl_header">Mode</td> <td class="tbl_header">Cheque No</td> <td class="tbl_header_right">Amount</td> <td class="tdempty"></td> </tr> <?php if(isset($stmt)) { while($row = $stmt->fetch()) {?> <tr> <td class="tdempty"></td> <td class="tbl_content"><?php echo $row['RCNo'];?></td> <td class="tbl_content"><?php echo date("d-m-Y", strtotime($row['RcDate']));?></td> <td class="tbl_content"><?php echo $row['Rcvdfor'];?></td> <td class="tbl_content"><?php echo $row['Mode'];?></td> <td class="tbl_content"><?php echo $row['ChqNo'];?></td> <td class="tbl_content_right"><?php echo number_format($row['Amount'],2) ;?></td> <td class="tdempty"></td> </tr> <?php $total+=$row['Amount']; }}?> <tr><td colspan="9"><hr /></td></tr> <tr> <td colspan="6"></td> <td class="tbl_subtotal_right"> <?php echo number_format($total,2);?></td> </tr> </table> <?php unset($dbh); unset($stmt); ?> <?php include '../templete/footer.php'; ?> print_head.php <?php include '../inc/connection.inc.php'; include_once '../inc/html_function.php'; $comp = $dbh->query("SELECT * FROM CompanyInfo"); $comp->execute(); while($row = $comp->fetch()) { $cname = $row['Name']; $caddress = $row['Address']; $ctel=$row['Tel']; $cfax=$row['Fax']; $cemail=$row['Email']; } ?> <!DOCTYPE html> <html lang="en"> <!--<META HTTP-EQUIV="REFRESH" CONTENT="120">--> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>HCK reporting Service-PHP</title> <link rel="shortcut icon" href="../image/102.ICO" /> <link rel="stylesheet" type="text/css" href="../css/print.css"> <!--<a href="http://www.silsnetwork.com"><img id="logo" src="../image/logo.jpg" alt="sils" /></a>--> <div class="title"><?php htmlout($cname)?></div> <div class="address"><?php htmlout($caddress)?></div> <div class="address">Tel:<?php htmlout($ctel)?> Fax:<?php htmlout($cfax)?> Email:<?php htmlout($cemail)?> </div> <div class="address"><hr /> </div> <div class="clickon_display"> <!--<a href="javascript:window.print();">Printed on :- <?php echo date("M d, Y"); ?> </a>--> </div> <!--<a href="javascript:window.print();"><?php echo $title; ?> </a>--> <!--<a href="javascript:window.print();"><h6>Titel of reports</h6></a>--> <script language="Javascript1.2"> function printpage() { window.print(); } </script> </head> <body onload="printpage()"> print.html.php <?php include '../templete/print_head.php'; $total=0; $scoursefee = 0; $sinipay = 0; $sdisc = 0; $scholar = 0; $nomonth = 0; $totalpaid=0; $balance=0; $totalother=0; $totaloverall=0; ?> <?php $sid = $_POST["sid"]; $s = $dbh->query("SELECT * FROM StudentRecord WHERE SID='$sid'"); $s->execute(); while($row = $s->fetch()) { $ssid = $row['SID']; $sname = $row['Name']; $snric = $row['NRIC']; $scoursecode = $row['CourseCode']; $spaytype = $row['PayMode']; $scoursefee = $row['CourseFee']; $sinipay = $row['IniPayment']; $sdisc = $row['Discount']; $scholar = $row['ScholarShip']; $nomonth = $row['NoMonths']; } $a = $dbh->query("SELECT SUM(Amount) as Amount FROM vwStatement WHERE SID='$sid'"); $a->execute(); while($row = $a->fetch()) { $totalpaid=$row['Amount']; } $balance=$scoursefee-$totalpaid; $b = $dbh->query("SELECT SUM(Amount) as Amount FROM vwStatementopen WHERE SID='$sid'"); $b->execute(); while($row = $b->fetch()) { $totaloverall=$row['Amount']; } $totalother=$totaloverall-$totalpaid ?> <div class="title">Statement</div> <hr /> <table align="center" cellpadding="1" cellspacing="1" style="width: 100%" > <tr> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Student ID</td> <td class="labeldesign_statement" style="width: 34px">:</td> <td class="labeldesign_statement"><?php echo htmlout($ssid);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Course Fee</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($scoursefee,2);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Total Paid(Fee)</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($totalpaid,2);?></td> </tr> <tr> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Student Name</td> <td class="labeldesign_statement" style="width: 34px">:</td> <td class="labeldesign_statement"><?php echo htmlout($sname);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Initial Payment</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($sinipay,2);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Balance(Fee)</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($balance,2);?></td> </tr> <tr> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">NRIC/PP</td> <td class="labeldesign_statement" style="width: 34px">:</td> <td class="labeldesign_statement"><?php echo htmlout($snric);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Discount</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($sdisc,2);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Total Paid(Others)</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($totalother,2);?></td> </tr> <tr> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Course</td> <td class="labeldesign_statement" style="width: 34px">:</td> <td class="labeldesign_statement"><?php echo htmlout($scoursecode);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Scholarship</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($scholar,2);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Total Paid(Overall)</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($totaloverall,2);?></td> </tr> <tr> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">Pay Type</td> <td class="labeldesign_statement" style="width: 34px">:</td> <td class="labeldesign_statement"><?php echo htmlout($spaytype);?></td> <td class="tdempty" style="width: 30px"></td> <td class="labeldesign_statement" style="width: 114px">No of Month</td> <td class="labeldesign_statement" style="width: 27px">:</td> <td class="labeldesign_statement"><?php echo number_format($nomonth);?></td> </tr> </table> <table width="100%" align="center" cellpadding="4" cellspacing="1"> <tr><td colspan="7"><hr /></td></tr> <tr> <td class="tdempty"></td> <td class="tbl_header">Receipt No</td> <td class="tbl_header">Receipt Date</td> <td class="tbl_header">Description</td> <td class="tbl_header">Mode</td> <td class="tbl_header">Cheque No</td> <td class="tbl_header_right">Amount</td> <td class="tdempty"></td> </tr> <tr><td colspan="7"><hr /></td></tr> <?php if(isset($stmt)) { while($row = $stmt->fetch()) {?> <tr> <td class="tdempty"></td> <td class="tbl_content"><?php echo $row['RCNo'];?></td> <td class="tbl_content"><?php echo date("d-m-Y", strtotime($row['RcDate']));?></td> <td class="tbl_content"><?php echo $row['Rcvdfor'];?></td> <td class="tbl_content"><?php echo $row['Mode'];?></td> <td class="tbl_content"><?php echo $row['ChqNo'];?></td> <td class="tbl_content_right"><?php echo number_format($row['Amount'],2) ;?></td> <td class="tdempty"></td> </tr> <?php $total+=$row['Amount']; }}?> <tr><td colspan="7"><hr /></td></tr> <tr> <td colspan="6"></td> <td class="tbl_subtotal_right"> <?php echo number_format($total,2);?></td> </tr> <tr><td colspan="7"><hr /></td></tr> </table> <?php unset($dbh); unset($stmt); ?> Please Help me Maideen Quote Link to comment https://forums.phpfreaks.com/topic/279199-print-report-data-to-printer/ Share on other sites More sharing options...
trq Posted June 15, 2013 Share Posted June 15, 2013 Sorry, your issue is what? Quote Link to comment https://forums.phpfreaks.com/topic/279199-print-report-data-to-printer/#findComment-1436109 Share on other sites More sharing options...
ginerjm Posted June 15, 2013 Share Posted June 15, 2013 Yes - what is your problem? I don't know what you mean about printing the page, since I see no code related to printing a page. But - fyi - printing with php is best done by creating a pdf and then letting the user trigger the print action with their browser. Very difficult to simply print a web page since you don't know how it appears to the user on his screen and may not fit on the page. With a pdf, you can create a well-defined image and be sure that it will be a nice-looking report. Read up on the fpdf class. It will take a little experimenting but it is easy to pick up. Quote Link to comment https://forums.phpfreaks.com/topic/279199-print-report-data-to-printer/#findComment-1436128 Share on other sites More sharing options...
maideen Posted June 16, 2013 Author Share Posted June 16, 2013 hi The above code works fine. no problem. when click the print button it opens two pages Print.html.php is printing page One is the printer dialog another is print.html.php with data. But i need only print dialog page. Pls help me maideen Quote Link to comment https://forums.phpfreaks.com/topic/279199-print-report-data-to-printer/#findComment-1436200 Share on other sites More sharing options...
trq Posted June 16, 2013 Share Posted June 16, 2013 A browser can not print a page that is not open. Quote Link to comment https://forums.phpfreaks.com/topic/279199-print-report-data-to-printer/#findComment-1436208 Share on other sites More sharing options...
ginerjm Posted June 16, 2013 Share Posted June 16, 2013 When you say "click the print button" are you talking about a button that you put on the page, or the browser's print button? Quote Link to comment https://forums.phpfreaks.com/topic/279199-print-report-data-to-printer/#findComment-1436257 Share on other sites More sharing options...
maideen Posted June 18, 2013 Author Share Posted June 18, 2013 Hi page button I have tried many way but results both page and printer dialog box appear. Pls help me. Maideen Quote Link to comment https://forums.phpfreaks.com/topic/279199-print-report-data-to-printer/#findComment-1436641 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.