<?php
// Database connection parameters
$servername = "localhost:3306";
$username = "rlmgloba_cotg";
$password = "pjWKw3r8&ZbzC5qm";
$dbname = "rlmgloba_cotg";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Get the input from the AJAX request
$input = isset($_POST['input']) ? $_POST['input'] : '';

// Prepare the SQL statement with placeholders
$stmt = $conn->prepare("SELECT * FROM maps WHERE LayoutName LIKE ? OR LongLink LIKE ? OR Sharestring LIKE ? OR Creator LIKE ? OR WaLa LIKE ? OR mapType LIKE ?");

// Add wildcard characters to the input
$inputWildcard = "%" . $input . "%";

// Bind parameters
$stmt->bind_param("ssssss", $inputWildcard, $inputWildcard, $inputWildcard, $inputWildcard, $inputWildcard, $inputWildcard);

// Execute the statement
$stmt->execute();

// Get the result
$result = $stmt->get_result();

// Check if there are any results
if ($result->num_rows > 0) {
    // Output data of each row
    echo "<table border='1' style='width:100%; text-align: left;'>
            <tr>
                <th>id</th>
                <th>LayoutName</th>
                <th>ShortLink</th>
                <th>LongLink</th>
                <th>Sharestring</th>
                <th>last_read</th>
                <th>created</th>
                <th>Creator</th>
                <th>WaLa</th>
                <th>mapType</th>
            </tr>";
    while ($row = $result->fetch_assoc()) {
        echo "<tr>
                <td>" . $row["id"] . "</td>
                <td>" . $row["LayoutName"] . "</td>
                <td>" . $row["ShortLink"] . "</td>
                <td>" . $row["LongLink"] . "</td>
                <td>" . $row["Sharestring"] . "</td>
                <td>" . $row["last_read"] . "</td>
                <td>" . $row["created"] . "</td>
                <td>" . $row["Creator"] . "</td>
                <td>" . $row["WaLa"] . "</td>
                <td>" . $row["mapType"] . "</td>
            </tr>";
    }
    echo "</table>";
} else {
    echo "No results found.";
}

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