How can PHP be used to dynamically display database entries and allow for status changes through forms?

To dynamically display database entries and allow for status changes through forms in PHP, you can use SQL queries to fetch the data from the database and populate the HTML table with the results. You can also use HTML forms to submit status changes, which can be processed using PHP to update the database accordingly.

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

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

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

// Display data in HTML table
echo "<table>";
echo "<tr><th>ID</th><th>Name</th><th>Status</th></tr>";
while($row = $result->fetch_assoc()) {
    echo "<tr>";
    echo "<td>".$row['id']."</td>";
    echo "<td>".$row['name']."</td>";
    echo "<td>".$row['status']."</td>";
    echo "<td><form method='post' action='update_status.php'><input type='hidden' name='id' value='".$row['id']."'><select name='status'><option value='active'>Active</option><option value='inactive'>Inactive</option></select><input type='submit' value='Update'></form></td>";
    echo "</tr>";
}
echo "</table>";

// Update status in database
if($_SERVER["REQUEST_METHOD"] == "POST") {
    $id = $_POST['id'];
    $status = $_POST['status'];
    $update_sql = "UPDATE entries SET status='$status' WHERE id=$id";
    $conn->query($update_sql);
}
?>