<?php
session_start();
require 'db_connection.php';

$student_id = intval($_GET['student_id'] ?? 0);

$stmt = $conn->prepare("
SELECT * FROM payments
WHERE student_id=?
ORDER BY created_at DESC
");

$stmt->bind_param("i", $student_id);
$stmt->execute();
$res = $stmt->get_result();
?>

<!DOCTYPE html>
<html>
<head>
<title>Payment History</title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

</head>
<body class="bg-light">

<div class="container mt-4">
<h3>Payment History</h3>

<table class="table table-bordered bg-white">
<tr>
<th>Amount</th>
<th>Purpose</th>
<th>Date</th>
<th>Receipt</th>
</tr>

<?php while($row = $res->fetch_assoc()): ?>
<tr>
<td>₦<?= number_format($row['amount'],2) ?></td>
<td><?= $row['purpose'] ?></td>
<td><?= $row['date'] ?></td>
<td>
<a href="receipt.php?receipt_no=<?= $row['receipt_no'] ?>">
<?= $row['receipt_no'] ?>
</a>
</td>
</tr>
<?php endwhile; ?>

</table>

</div>

</body>
</html>