计算在javascript中打印函数调用的次数

I have a the following code

<?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>

the following code print this page

<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>

at the following line I want to get the receipt number which will auto generate wherever print function call either with php javascript or 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>

Please help me out.

Define a variable used to count, and increase it by one every time you print the page.

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