What is the best practice for adding links in a PHP table to allow for editing existing data records?
When adding links in a PHP table to allow for editing existing data records, the best practice is to include a unique identifier for each record in the link URL. This identifier can be passed as a parameter to the editing page, where the record can be retrieved and modified. This ensures that the correct record is being edited and provides a seamless user experience.
// Assuming $records is an array of data records
echo "<table>";
echo "<tr><th>ID</th><th>Name</th><th>Action</th></tr>";
foreach ($records as $record) {
echo "<tr>";
echo "<td>" . $record['id'] . "</td>";
echo "<td>" . $record['name'] . "</td>";
echo "<td><a href='edit.php?id=" . $record['id'] . "'>Edit</a></td>";
echo "</tr>";
}
echo "</table>";