PHP Code:
while ($author = mysql_fetch_array($authors)){
$id = $author['id'];
$name = $author['name'];
echo '<tr><td>' . $name . '</td><td><input type="checkbox" name="delete[]" value="' . $id . '" /></td></tr>';
} // end of while
The above code put inside your form tags will produce a row in your table for each author, with a checkbox beside the name. I'm assuming that you'll use POST to send your form data.
PHP Code:
<?php
foreach($_POST['delete'] AS $id){
$sql = "DELETE FROM author WHERE id='$id'";
if (@mysql_query($sql)){
echo 'Author deleted';
} else {
echo 'Unable to delete author' . mysql_error();
}
}
?>
This code takes the array passed to it from the form and steps through each element one by one using the id number to delete that record from the database.
Bookmarks