亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

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