php page send to print

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

maideen
New php-forum User
New php-forum User
Posts: 27
Joined: Mon Mar 07, 2011 11:38 pm

php page send to print

Postby maideen » Thu May 30, 2013 4:16 am

Hi
Following code is working fine. But On click the print button it display data on another page not going to print. Can any body know, pls let me know. Pls help me

It is HTML Page

Code: Select all

<style type="text/css"></style>
<?php
include '../templete/header.php';
?>

<Script Language="javascript">
function change_action()
    {
        var frm_obj=document.getElementById("frm");
        frm_obj.action="data.php";
    }
</Script>



<table class="tbl_table" align="center">
<form action="" method="POST" id="frm" >
    <tr>
        <td class="td_title" colspan="2"><strong>Outstanding Balance Report</strong></td>
    </tr>
      <tr>
        <td class="td_class_right">Until:</td>
        <td><input class="textdesign" type="text" id="datepicker1" name="datefrom" /></td>
      </tr>

        <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

Code: Select all

<?php
include_once '../inc/connection.inc.php';
?>
<?php
if (isset($_POST['search']) && $_POST['search']  != "" )
    {
        $datefrom=$_POST["datefrom"];
        $s = $dbh->prepare("EXECUTE usp_OutStanding_Balance ?");
        $s->bindParam(1, $datefrom, PDO::PARAM_STR);
        $stmt = $s->execute();
       
        $stmt = $dbh->query("SELECT * FROM vw_OutStanding_Balance ORDER BY MVName"); 
        $stmt->setFetchMode(PDO::FETCH_ASSOC); 
        include 'view.html.php';
     }
   
 
?>

<?php
if (isset($_POST['print']) && $_POST['print']  != "" )
    {
        $datefrom=$_POST["datefrom"];
        $s = $dbh->prepare("EXECUTE usp_OutStanding_Balance ?");
        $s->bindParam(1, $datefrom, PDO::PARAM_STR);
        $stmt = $s->execute();
       
        $stmt = $dbh->query("SELECT * FROM vw_OutStanding_Balance ORDER BY MVName"); 
        $stmt->setFetchMode(PDO::FETCH_ASSOC); 
        include 'print.html.php';
     }
   
 
?>


view.html.php

Code: Select all

<?php
include '../templete/header.php';

?>

<?php 
$groupby = '';
$displaySubTotal = FALSE;

$subTotal = 0;
$grandTotal = 0;

$sub_debit=0;  // maideen
$grn_debit=0;  // maideen

$sub_credit=0;  // maideen
$grn_credit=0;  // maideen

$sub_bal=0;  // maideen
$grn_bal=0;  // maideen


?>

    <table width="100%" align="center" cellpadding="4" cellspacing="1" class=tbl_table">
        <tr>
            <td class="tdempty"></td>
            <td class="tbl_header">MV CODE</td>
            <td class="tbl_header">MV NAME</td>
            <td class="tbl_header_right">DEBIT</td>
            <td class="tbl_header_right">CREDIT</td>
            <td class="tbl_header_right">BALANCE</td>
            <td class="tdempty"></td>
   
           
        </tr>
        <?php if(isset($stmt))
        {
        while($row = $stmt->fetch()):
              if($groupby!=$row['MVName']):
             
                if($displaySubTotal): ?>
                   
               <?php
                   
                     
                     $grn_debit += $sub_debit;
                     $sub_debit=0;
                     
                     $grn_credit += $sub_credit;
                     $sub_credit=0;
                     
                     $grn_bal += $sub_bal;
                     $sub_bal=0;
                else:
                      $displaySubTotal = TRUE;
                endif;
                      $groupby = $row['MVName'];
                     
                endif;
                ?>
            <tr>
                <td class="tdempty"></td>
                <td class="tbl_content"><?php echo $row['MVcode'];?></td>
                <td class="tbl_content"><?php echo $row['MVName'];?></td>
                <td class="tbl_content_right"><?php echo number_format($row['Debit'],2) ;?></td>
                <td class="tbl_content_right"><?php echo number_format($row['Credit'],2) ;?></td>
                <td class="tbl_content_right"><?php echo number_format($row['Balance'],2) ;?></td>
                <td class="tdempty"></td>
             </td>
             
            <?php
                 
                 $sub_debit += $row['Debit'];
                 $sub_credit += $row['Credit'];
                 $sub_bal += $row['Balance'];
                 
                 endwhile;
                 
                 $grn_debit += $sub_debit;
                 $grn_credit += $sub_credit;
                 $grn_bal += $sub_bal;
            ?>
 
        <tr><td colspan="6"><hr /></td></tr>
        <tr>
            <td colspan="2">
            <td class="tbl_subtotal_left"><b>Grand Total</b></td>
            <td class="tbl_subtotal_right"><b><?php echo number_format($grn_debit,2); ?></b></td>
            <td class="tbl_subtotal_right"><b><?php echo number_format($grn_credit,2); ?></b></td>
            <td class="tbl_subtotal_right"><b><?php echo number_format($grn_bal,2); ?></b></td>
           
        </tr>
        <tr><td colspan="6"><hr /></td></tr>
        <?php }?>
    </table>
   <?php unset($dbh); unset($stmt); ?>

<?php
include '../templete/footer.php';
?>


print.html.php

Code: Select all

<?php
include '../templete/print_head.php';

?>

<?php 
$groupby = '';
$displaySubTotal = FALSE;

$subTotal = 0;
$grandTotal = 0;

$sub_debit=0;  // maideen
$grn_debit=0;  // maideen

$sub_credit=0;  // maideen
$grn_credit=0;  // maideen

$sub_bal=0;  // maideen
$grn_bal=0;  // maideen


?>
<div class="title">Outstanding Report</div>
    <table width="100%" align="center" cellpadding="4" cellspacing="1" class=tbl_table">
        <tr><td colspan="6"><hr /></td></tr>
        <tr>
            <td class="tdempty"></td>
            <td class="tbl_header">MV CODE</td>
            <td class="tbl_header">MV NAME</td>
            <td class="tbl_header_right">DEBIT</td>
            <td class="tbl_header_right">CREDIT</td>
            <td class="tbl_header_right">BALANCE</td>
            <td class="tdempty"></td>
   
           
        </tr>
        <tr><td colspan="6"><hr /></td></tr>
        <?php if(isset($stmt))
        {
        while($row = $stmt->fetch()):
              if($groupby!=$row['MVName']):
             
                if($displaySubTotal): ?>
                   
               <?php
                   
                     
                     $grn_debit += $sub_debit;
                     $sub_debit=0;
                     
                     $grn_credit += $sub_credit;
                     $sub_credit=0;
                     
                     $grn_bal += $sub_bal;
                     $sub_bal=0;
                else:
                      $displaySubTotal = TRUE;
                endif;
                      $groupby = $row['MVName'];
                     
                endif;
                ?>
            <tr>
                <td class="tdempty"></td>
                <td class="tbl_content"><?php echo $row['MVcode'];?></td>
                <td class="tbl_content"><?php echo $row['MVName'];?></td>
                <td class="tbl_content_right"><?php echo number_format($row['Debit'],2) ;?></td>
                <td class="tbl_content_right"><?php echo number_format($row['Credit'],2) ;?></td>
                <td class="tbl_content_right"><?php echo number_format($row['Balance'],2) ;?></td>
                <td class="tdempty"></td>
             </td>
             
            <?php
                 
                 $sub_debit += $row['Debit'];
                 $sub_credit += $row['Credit'];
                 $sub_bal += $row['Balance'];
                 
                 endwhile;
                 
                 $grn_debit += $sub_debit;
                 $grn_credit += $sub_credit;
                 $grn_bal += $sub_bal;
            ?>
 
        <tr><td colspan="6"><hr /></td></tr>
        <tr>
            <td colspan="2">
            <td class="tbl_subtotal_left"><b>Grand Total</b></td>
            <td class="tbl_subtotal_right"><b><?php echo number_format($grn_debit,2); ?></b></td>
            <td class="tbl_subtotal_right"><b><?php echo number_format($grn_credit,2); ?></b></td>
            <td class="tbl_subtotal_right"><b><?php echo number_format($grn_bal,2); ?></b></td>
           
        </tr>
        <tr><td colspan="6"><hr /></td></tr>
        <?php }?>
    </table>
   <?php unset($dbh); unset($stmt); ?>


Pls help me

Maideen

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: php page send to print

Postby johnj » Thu May 30, 2013 6:11 am

printing is a client side activity. If you are using Windows OS, then after opening the report in a new page, just do window.print()

maideen
New php-forum User
New php-forum User
Posts: 27
Joined: Mon Mar 07, 2011 11:38 pm

Re: php page send to print

Postby maideen » Thu May 30, 2013 4:01 pm

hi john

I have tested but appear page with data but not output printers.

where this command should be given? I have given top of page but no response.

Pls

Maideen

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: php page send to print

Postby johnj » Fri May 31, 2013 7:53 am

you have to give this in the javascript that gets executed when the print button is clicked.


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron