How can the PHP script be modified to include a button for editing data in the display?

To include a button for editing data in the display, you can add a new column in the table that contains the data with a button for editing. This button can redirect the user to a separate page where they can edit the data. In the PHP script, you can check if the button is clicked and handle the editing functionality accordingly.

<?php
// Displaying data in a table with an edit button
echo "<table>";
echo "<tr><th>ID</th><th>Name</th><th>Email</th><th>Action</th></tr>";

// Loop through the data and display each row with an edit button
foreach($data as $row) {
    echo "<tr>";
    echo "<td>".$row['id']."</td>";
    echo "<td>".$row['name']."</td>";
    echo "<td>".$row['email']."</td>";
    echo "<td><a href='edit.php?id=".$row['id']."'>Edit</a></td>";
    echo "</tr>";
}

echo "</table>";

// Edit functionality in edit.php
if(isset($_GET['id'])) {
    $id = $_GET['id'];
    
    // Fetch data for the selected ID and display it in a form for editing
    // Update the data in the database upon form submission
}
?>