<?php
session_start();
include("config.php");

$uid = $_SESSION['uid'] ?? 0;

if (!$uid) {
    echo "Not logged in";
    exit;
}

$conn = new mysqli(
    $config['db_host'],
    $config['db_user'],
    $config['db_pass'],
    $config['db_name']
);

if ($conn->connect_error) {
    die("DB error");
}

$sql = "SELECT * FROM thevani WHERE balakedara = ? ORDER BY shonu DESC LIMIT 20";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $uid);
$stmt->execute();
$result = $stmt->get_result();

echo "<h3>Your Recent Orders</h3>";
while ($row = $result->fetch_assoc()) {
    echo "<div>";
    echo "<b>Order:</b> " . htmlspecialchars($row['dharavahi']) . "<br>";
    echo "<b>Amount:</b> ₹" . htmlspecialchars($row['motta']) . "<br>";
    echo "<b>Status:</b> " . ($row['sthiti'] == 1 ? "Success" : "Pending") . "<br>";
    echo "<hr>";
    echo "</div>";
}

$stmt->close();
$conn->close();
?>