if (isset($_POST['submit'])) { foreach ($_POST['todelete'] as $delete_id) { //这里是循环遍历这个数组 todelete 每一个值被设置成 $delete_id $query = "DELETE FROM email_list WHERE id = $delete_id"; mysqli_query($dbc, $query) or die('Error querying database.'); } echo 'Customer(s) removed.<br />'; } // Display the customer rows with checkboxes for deleting $query = "SELECT * FROM email_list"; $result = mysqli_query($dbc, $query); while ($row = mysqli_fetch_array($result)) {
// todelete[]是一个数组 能够把checkbox中选中的放到这个数组中 echo '<input type="checkbox" value="' . $row['id'] . '" name="todelete[]" />'; echo $row['first_name']; echo ' ' . $row['last_name']; echo ' ' . $row['email']; echo '<br />'; }