2014-08-31 42 views
-3

我在下面的行有下面的代码指望有多少次我打印功能调用javascript中

<?php 
ob_start(); 
include '../connection.php'; 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Easy Installment Motorcycle Scheme Haripur</title> 

下面的代码打印此页

<script type="text/javascript"> 
function printpage() 
    { 
    window.print(); 
    } 
</script> 
</head> 

<body onload="printpage()"> 
<div style="width:500px; margin-left:50px"> 
<?php 
$sSql="SELECT * FROM landing_page WHERE status='active'"; 
$result=mysqli_query($con,$sSql); 
if(!$result){ 
    die(mysqli_error($con)); 
    } 
$row=mysqli_fetch_array($result); 

?> 
<h2 style="text-align:center">Receipt For <?php echo $row['schemeName'];?></h2> 

想要得到的收据号码这将自动生成无论打印函数调用任何地方使用PHP的JavaScript或HTML

<h3>Receipt No: </h3> 
<?php 
$sSql="SELECT * FROM draw_date_time"; 
$result=mysqli_query($con,$sSql); 
if(!$result){ 
    die(mysqli_error($con)); 
    } 
$row=mysqli_fetch_array($result); 
?> 
<h3>Draw Date: <u><?php echo $row['date_of_draw'];?></u> &nbsp; Draw Time: <u><?php echo $row['time_of_draw'];?></u> &nbsp; Draw Place: <u><?php echo $row['draw_address'];?></u></h3> 
<?php 
$reg_number=$_POST['reg_number']; 
$month=date('Y-m-d',strtotime($_POST['month'])); 
$sSql="SELECT * 
FROM users u LEFT JOIN 
    installments i 
    ON u.id = i.fk_users_id 
WHERE u.reg_number = '$reg_number' AND i.month='$month' 
LIMIT 0 , 30"; 
$result=mysqli_query($con,$sSql); 
if(!$result){ 
    die(mysqli_error($con)); 
    } 
$row=mysqli_fetch_array($result); 
?> 
<h2>Memebership No: <u><?php echo ucfirst($row['reg_number']);?></u></h2> 
<table width="500" border="1" style="text-align:left"> 
    <tr> 
    <th scope="row">Memeber Name</th> 
    <td><?php echo ucfirst($row['user_name']);?></td> 
      <th scope="row">Father Name</th> 
    <td><?php echo ucfirst($row['father_name']);?></td> 
    </tr> 
    <tr> 
    <th scope="row">Phone No</th> 
    <td><?php echo $row['phone'];?></td> 
    <th scope="row">CNIC No</th> 
    <td><?php echo $row['cnic'];?></td> 
    </tr> 
    <tr> 
    <th scope="row">Address</th> 
    <td><?php echo $row['address'];?></td> 
    <th scope="row">Receiver Name & address</th> 
    <td><?php echo $row['name_adrs_recvr'];?></td> 
    </tr> 
    <tr> 
    <th scope="row">Prv Arrear</th> 
    <td><?php echo $row['prv_arrear'];?></td> 
    <th scope="row">Amount</th> 
    <td><?php echo $row['amount'];?></td> 
    </tr> 
    <tr> 
    <th scope="row">Total</th> 
    <td><?php echo $row['total'];?></td> 
    <th scope="row">Receive</th> 
    <td><?php echo $row['receive'];?></td> 
    </tr> 
    <tr> 
    <th scope="row">Arrear</th> 
    <td><?php echo $row['arrear'];?></td> 
    <th scope="row">Date Receive</th> 
    <td><?php echo date('d-m-Y',strtotime($row['month']));?></td> 
    </tr> 
</table> 
<?php 
       $sql="SELECT * FROM landing_page WHERE status='active'"; 
       $result=mysqli_query($con, $sql); 
       $row=mysqli_fetch_assoc($result); 
       ?> 
       <fieldset> 
       <legend><img src="images/termsHead.png" style="float:right" /></legend> 
       <p><img src="../images/<?php echo $row['image2'];?>" width="400" height="300" /></p> 
       </fieldset> 
</div> 
</body> 
</html> 

请帮助我出去了。

+0

您可以在javascript中创建一个全局变量计数并设置为0.然后在每次调用printpage()时增加计数。 – 2014-08-31 09:54:48

回答

0

定义一个用于计数的变量,并在每次打印页面时增加一个。

var printed = 0; 
function printPage() { 
    print(); // "window." isn't needed 
    printed += 1; // Adds 1 
    alert(printed); // Alerts you overall how many times 
}; 
+0

它不工作我想我问了一些错误我正在编辑我的问题,并告诉你整个代码。 – TinyCoder 2014-08-31 10:06:43