<?php
session_start();
include 'config.php';
$user_id = $_SESSION['user_id'];
$q = $conn->query("SELECT * FROM purchases WHERE user_id=$user_id ORDER BY id DESC");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>History</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
</head>
<body class="bg-black text-white p-4">
    <div class="max-w-lg mx-auto">
        <h2 class="text-2xl font-bold mb-4">My History</h2>
        <a href="dashboard.php" class="mb-4 inline-block text-cyan-400">Back</a>
        <div class="space-y-3">
            <?php while($row = $q->fetch_assoc()): ?>
            <div class="bg-gray-900 p-4 rounded border border-gray-800 flex justify-between items-center">
                <div>
                    <h4 class="font-bold"><?php echo $row['phone_name']; ?></h4>
                    <p class="text-xs text-gray-500"><?php echo $row['purchase_date']; ?></p>
                </div>
                <a href="result.php?id=<?php echo $row['id']; ?>" class="bg-cyan-600 px-3 py-1 rounded text-sm">View</a>
            </div>
            <?php endwhile; ?>
        </div>
    </div>
</body>
</html>