<?php
include "config.php";
$id=$_GET['id'];

$b=mysqli_fetch_assoc(mysqli_query($conn,"
SELECT bills.*,patients.name
FROM bills
JOIN patients ON bills.patient_id=patients.id
WHERE bills.id='$id'
"));
?>

<h2>Clinic Invoice</h2>

Patient: <?= $b['name'] ?><br>
Bill No: <?= $b['id'] ?><br>

<hr>

<table border="1">
<tr><th>Item</th><th>Amount</th></tr>

<?php
$r=mysqli_query($conn,"SELECT * FROM bill_items WHERE bill_id='$id'");
while($row=mysqli_fetch_assoc($r)){
echo "<tr>
<td>{$row['item']}</td>
<td>{$row['amount']}</td>
</tr>";
}
?>

<tr>
<th>Total</th>
<th><?= $b['total'] ?></th>
</tr>
</table>

<br>
<button onclick="window.print()">Print</button>