Home  >  Article  >  Backend Development  >  How to achieve batch deletion of check boxes in php

How to achieve batch deletion of check boxes in php

藏色散人
藏色散人Original
2021-03-01 09:51:492943browse

php method to implement batch deletion of check boxes: first connect to the database and obtain a table; then create a form and define a check box; then add a batch delete button; and finally create a PHP process for deletion page.

How to achieve batch deletion of check boxes in php

#The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

php batch deletion, batch operation

Delete multiple records in batches. For relatively large amounts of information, it is very troublesome if there is no batch deletion function.

1. Take a table from the database and write a check box to select

You can add a check box to select all Selection box

Nothing to connect to the database is written

Code:

<form action="piliangshanchu.php" method="post" >


 
<table border="1" cellspacing="0" cellpadding="0">
    <tr>

        <td width="200">
            <input type="checkbox" value="&#39;&#39;" name="dx" onclick="checkall(this)" />
            编号</td>
        <td width="200">姓名</td>
        <td width="200">电话</td>
        <td width="200" >分组</td>
        <td width="200" >操作</td>
    </tr>
<tr>
        <td>
        <input type=&#39;checkbox&#39; value=&#39;{$attr[0]}&#39; name=&#39;item[]&#39; class=&#39;ck&#39; />
        {$attr[0]}</td> 

        <td>{$str}</td>
        <td>{$attr[2]}</td>
        <td>{$nation}</td>
</tr>


</table>

    <input type="submit" value="批量删除"/>
    </form>

Plus a batch delete button

Above picture:

If I click to select all, I can easily select all by using js click event

Code:

3f1c4e4b6b16bbbd69b2ee476dc4f83a
    function xxx(qx)
    {//全选多选的选中状态
        var ck = document.getElementsByClassName("ck");  //让下面所有的多选选中状态改变
        if(qx.checked)
        {            for(i = 0;i 26e5c2fad16db7e8cf031a7166d0b99b

2. Deletion processing page

Code:

<?php
$arr = $_POST["item"];
$db = new mysqli("localhost","root","12345678","heiheihei");
//foreach($arr as $v)
//{
//    $sql = "delete from contacts WHERE id=&#39;{$v}&#39;";
//    $db->query($sql);
//}
$str = implode("&#39;,&#39;",$arr);//拼接字符,
$sql = "delete from contacts WHERE id in(&#39;{$str}&#39;)";
//2&#39;,&#39;8&#39;,&#39;4
if($db->query($sql))//判断是否查询成功,
{
    header("location:shouye.php");
    //成功就跳转
}



?>

The data transmission using foreach is too slow, and there are many deletions and traversals, so it is judged directly. [Recommended learning: "PHP Video Tutorial"]

The above is the detailed content of How to achieve batch deletion of check boxes in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn