<?php
require_once '../connection.php';

// Function to display table data
function displayTable($conn, $tableName) {
    echo "<h2>Contents of $tableName</h2>";
    $result = $conn->query("SELECT * FROM $tableName LIMIT 10");
    
    if ($result && $result->num_rows > 0) {
        echo "<table border='1' cellpadding='5'>";
        // Table header
        echo "<tr>";
        while ($field = $result->fetch_field()) {
            echo "<th>" . $field->name . "</th>";
        }
        echo "</tr>";
        
        // Table data
        while ($row = $result->fetch_assoc()) {
            echo "<tr>";
            foreach ($row as $value) {
                echo "<td>" . htmlspecialchars($value) . "</td>";
            }
            echo "</tr>";
        }
        echo "</table>";
    } else {
        echo "No data found or error: " . $conn->error . "<br>";
    }
    echo "<br>";
}

// Check if we're connected to the database
if (isset($conn) && $conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

echo "<h1>Database: xesstech_dayloan</h1>";

// Display registration table
displayTable($conn, 'registration');

// Display collection_agent table
displayTable($conn, 'collection_agent');

// Close connection
$conn->close();
?>
