I have button print if i click that button only print last row in my table. that button i use for show data from correct row and print that. table image
My query use PDO php. This table code and javascript function:
<tbody>
<?php foreach($pembelian_polowijo as $pp){ ?>
<tr>
<td><?php echo $pp->nomer; ?></td>
<td><?php echo $pp->tanggal_pembelian; ?></td>
<td><?php echo $pp->nama_penjual; ?></td>
<td><?php echo $pp->nama_barang; ?></td>
<td><?php echo $pp->berat; ?></td>
<td><?php echo $pp->harga_beli; ?></td>
<td><?php echo $pp->berat*$pp->harga_beli; ?></td>
<td><?php echo $pp->setatus; ?></td>
<td><button onclick="gg('2');">Print</button>
<script type="text/javascript">
var printer = new Recta('8388907235', '1811')
function gg() {
printer.open().then(function () {
printer.align('center')
.text('<?php echo $pp->nomer; ?>')
.bold(false)
.text('<?php echo $pp->tanggal_pembelian; ?>')
.bold(false)
.text('<?php echo $pp->nama_penjual; ?>')
.bold(false)
.text('<?php echo $pp->nama_barang; ?>')
.bold(false)
.text('<?php echo $pp->berat; ?>')
.bold(false)
.text('<?php echo $pp->harga_beli; ?>')
.bold(false)
.text('<?php echo $pp->berat*$pp->harga_beli; ?>')
.bold(false)
.cut()
.print()
})
}
</script>
</td>
</tr>
<?php } ?>
</tbody>
HTML Code
<td><button onclick="gg( '<?php echo json_encode( $pp ); ?>' );">Print</button>
Javascript Code
<script type="text/javascript">
var printer = new Recta('8388907235', '1811')
function gg( dataForPrint ) {
printer.open().then(function () {
printer.align('center')
.text( dataForPrint.nomer)
.bold(false)
.text(dataForPrint.tanggal_pembelian)
.bold(false)
.text(dataForPrint.nama_penjual)
.bold(false)
.text( dataForPrint.dataForPri )
.bold(false)
.text( berat )
.bold(false)
.text( dataForPrint.harga_beli )
.bold(false)
.text( Number(dataForPrint.berat) * Number(dataForPrint.harga_beli))
.bold(false)
.cut()
.print()
})
}
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.