How to print a page by using iframe inside php while loop
say I have a php code and javascript like this:
$qry=("SELECT * FROM tbl");
$result=mysqli_query($con,$qry);
while($test = mysqli_fetch_array($result)) { ?>
<tr>
<td><?php echo $test['staff_id']; ?></td>
<td><?php echo $test['name']; ?></td>
<td><?php echo $test['rank']; ?></td>
<td><a href="#" onclick="printPg()" >
<img src="src/img/print.jpeg" height="25" /></a>
<div id="printerDiv" style="display:none"></div>
<script>
function printPg()
{
var div = document.getElementById("printerDiv");
div.innerHTML = '<iframe src="print.php?id=<?php echo $test['sn']; ?>" onload="this.contentWindow.print();"></iframe>';
}
</script>
</td>
</tr>
<?php } ?>
If I click on print image in any row, it only prints the last row of the table.
Any help will be greatly appreciated.