Hi
I am working on a payroll project and I am coding with php,html,js and mysql on xampp server. I have a salary sheet code which needs to be printed in pdf format for each employee with their names as the pdf filename.
on running the php page the js code triggers automatically and generates pdf files but the problem is the salary data of the first employee is printed on every payslip but
The filename changes with every pdf.
for example :
1st emp name is rajesh rao, 2nd emp name is a.ghosh.
now when I print the sheets, then 2 pdf files are created for these 2 employees with their names as filenames but the salary data is not changing on the 2nd emp sheet/
Any Help will be appreciated
<HTML>
<HEAD>
<TITLE>Salary Sheet</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="pure-blog/css/home.css" />
<link rel="stylesheet" href="pure-blog/css/pure-min.css" />
<link rel="stylesheet" href="pure-blog/css/pure-u.css" />
<link rel="stylesheet" href="pure-blog/css/pure-form.css" />
<link rel="stylesheet" href="pure-blog/css/pure-menu.css" />
<link rel="stylesheet" href="pure-blog/css/pure-table.css" />
</HEAD>
<BODY>
<?php
include "connect.php";
$cde = 1;
while ($cde < 3) {
$mysql = "SELECT * FROM emp_ndata WHERE ID = '$cde' ";
$myquery = mysqli_query($con, $mysql);
if(! $myquery ) {
die('Could not get data: ' . mysql_error());
}
$row = mysqli_fetch_array($myquery, MYSQLI_ASSOC);
?>
<div id="pdata" class="printArea">
<div class="pure-img" style="text-align:left">
<img src="pure-blog/img/companyLogoFull-pdf.png">
</div>
<table class="table_for_showdata table_for_showdata_small">
<tr>
<th colspan="2">
Salary Sheet of <b class="table_for_showdata_lg">
<?php echo $row['Emp_Name']; ?></b> : <?php echo $row ['Emp_psmonth']; ?> , <?php echo $row ['Emp_psyear']; ?>
</th>
</tr>
<tr>
<td>Emp-Code</td>
<td><?php echo $row['Emp_ID']; ?></td>
</tr>
<tr>
<td>Designation</td>
<td><?php echo $row['Emp_Designation']; ?></td>
</tr>
<tr>
<th colspan="2">EARNINGS</th>
</tr>
<tr>
<td >Basic</td>
<td><?php echo round($row ['Emp_Basic']).".00"; ?></td>
</tr>
<tr>
<td >House Rent Allowance</td>
<td><?php echo round($row ['Emp_HRA']).".00"; ?></td>
</tr>
<tr>
<th >DEDUCTIONS</th>
<th> </th>
</tr>
<tr>
<td >Professional Tax</td>
<td><?php echo $row ['Emp_Proffessional_Tax'].".00"; ?></td>
</tr>
<tr>
<td >Provident Fund</td>
<td><?php echo $row ['Emp_Provident_Fund'].".00"; ?></td>
</tr>
<tr>
<th > </th>
<th> </th>
</tr>
<tr>
<td class="tab_head_blue"><b>TOTAL PAY : </td>
<td style="font-size:18px"><b>Rs.<?php echo $row ['Emp_Total_Pay'].".00"; ?></b></td>
</tr>
</table>
</div>
<script type="text/javascript">
function printDiv() {
var divToPrint = document.getElementById('pdata');
var popupWin = window.open('', '_blank', 'width=1100,height=400');
popupWin.document.open();
document.title = "<?php echo $row['Emp_Name']; ?>";
popupWin.document.write('<html><head><title>' + document.title + '</title>');
popupWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
popupWin.document.close();
}
</script>
<script>
printDiv();
</script>
<?php
$GLOBALS['cde']++;
}
?>
</BODY>
</HTML>