How can PHP be used to output table contents with checkboxes for deletion similar to phpMyAdmin?

To output table contents with checkboxes for deletion similar to phpMyAdmin, you can create a PHP script that retrieves data from a database table and generates an HTML table with checkboxes for each row. Users can then select which rows they want to delete and submit the form to execute the deletion process.

<?php
// Connect to database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

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

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

// Retrieve data from database
$sql = "SELECT * FROM table";
$result = $conn->query($sql);

// Output table with checkboxes
echo "<form action='delete.php' method='post'>";
echo "<table>";
echo "<tr><th></th><th>Column 1</th><th>Column 2</th></tr>";
while($row = $result->fetch_assoc()) {
    echo "<tr>";
    echo "<td><input type='checkbox' name='delete[]' value='" . $row['id'] . "'></td>";
    echo "<td>" . $row['column1'] . "</td>";
    echo "<td>" . $row['column2'] . "</td>";
    echo "</tr>";
}
echo "</table>";
echo "<input type='submit' value='Delete Selected Rows'>";
echo "</form>";

$conn->close();
?>