2014-08-31 48 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