国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Delete users in batches and specific ones

Determine whether to delete a single selection or multiple selections

1. A single line is written to the delete.php file through get parameters. The corresponding ID.

2. For multiple deletions, the corresponding ID is passed to the delete.php page through POST.

3. If neither of these two is met, then we can regard the data as illegal.

if (is_array($_POST['id'])) {
    $id = join(',', $_POST['id']);
} elseif (is_numeric($_GET['id'])) {
    $id = (int) $_GET['id'];
} else {
    echo '數(shù)據(jù)不合法';
    exit;
}

Combined SQL statements

We have previously explained to you in the MySQL chapter that you can use the in sub-statement when deleting.

Similarly here, we can use the in sub-statement to achieve the effect.

The join function changes the id passed by multi-select deletion into the format of 3,4,5. The final effect of executing the SQL statement of multi-select deletion is:

delete from user where id in(3,4,5,6,8);

The effect of the single-select delete statement is:

delete from user where id in(3)

This way We have achieved single-selection and multi-selection adaptive effects.

$sql = "delete from user where id in($id)";

The final complete code demonstration is as follows:

<?php
include 'connection.php';
if (is_array($_POST['id'])) {
    $id = join(',', $_POST['id']);
} elseif (is_numeric($_GET['id'])) {
    $id = (int) $_GET['id'];
} else {
    echo '數(shù)據(jù)不合法';
    exit;
} 
$sql = "delete from user where id in($id)";
$result = mysqli_query($conn, $sql);
if ($result) {
    echo '刪除成功';
} else {
    echo '刪除失敗';
}


Continuing Learning
||
<?php include 'connection.php'; if (is_array($_POST['id'])) { $id = join(',', $_POST['id']); } elseif (is_numeric($_GET['id'])) { $id = (int) $_GET['id']; } else { echo '數(shù)據(jù)不合法'; exit; } $sql = "delete from user where id in($id)"; $result = mysqli_query($conn, $sql); if ($result) { echo '刪除成功'; } else { echo '刪除失敗'; }
submitReset Code