<?php
require_once __DIR__ . '/config/db.php';


echo "<h2>Orders Table Structure</h2>";
$result = $conn->query("DESCRIBE orders");
if (!$result) {
    echo "Error: " . $conn->error;
    exit;
}

echo "<table border='1' style='border-collapse: collapse; padding: 10px;'>";
echo "<tr style='background: #333; color: white;'><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default</th><th>Extra</th></tr>";
while($row = $result->fetch_assoc()) {
    echo "<tr>";
    echo "<td>" . $row['Field'] . "</td>";
    echo "<td>" . $row['Type'] . "</td>";
    echo "<td>" . $row['Null'] . "</td>";
    echo "<td>" . $row['Key'] . "</td>";
    echo "<td>" . ($row['Default'] ?? 'NULL') . "</td>";
    echo "<td>" . $row['Extra'] . "</td>";
    echo "</tr>";
}
echo "</table>";

echo "<h2>Sample Order Data</h2>";
$result = $conn->query("SELECT * FROM orders LIMIT 2");
if($result->num_rows > 0) {
    echo "<table border='1' style='border-collapse: collapse; margin-top: 20px;'>";
    $fields = $result->fetch_fields();
    echo "<tr style='background: #333; color: white;'>";
    foreach($fields as $field) {
        echo "<th>" . $field->name . "</th>";
    }
    echo "</tr>";
    
    $result = $conn->query("SELECT * FROM orders LIMIT 2");
    while($row = $result->fetch_assoc()) {
        echo "<tr>";
        foreach($row as $value) {
            echo "<td>" . (is_null($value) ? 'NULL' : htmlspecialchars(substr($value, 0, 50))) . "</td>";
        }
        echo "</tr>";
    }
    echo "</table>";
} else {
    echo "<p>No orders found</p>";
}

$conn->close();
?>
