Bulk deletion of multiple records, for more information, if there is no bulk deletion feature is very cumbersome.
1. Take a table from the database, write a check box to select
You can add a Select all check box
Connect to the database, not even write anything.
Code:
<form action= "piliangshanchu.php" method= "POST" ><table border= "1" cellspacing= "0" cellpadding= "0" > <tr> <td width= "$" > <input type= "checkbox" value= "" "Name=" DX "onclick=" Checkall (This) "/ > number </td> <td width= "$" > name </td> <td width= "$" > Phone </td> < TD width= > Group </td> <td width= "$" > Action </td> </tr><tr> <td> <input type= ' checkbox ' value= ' {$attr [0]} ' name= ' item[] ' class= ' ck '/> {$attr [0]}</td> <td>{$str}</td> <td>{$attr [2]}</td> <td>{$ nation}</td></tr></table> <input type= "Submit" value= "bulk Delete"/> </form>
Plus a bulk delete button
:
If I click the Select all, the use of JS Click event can be easily implemented by the full selection
Code:
<script> function xxx (QX) {//Select all selected multiple selection var ck = document.getelementsbyclassname ("ck"); Let all of the following multiple select states change if (qx.checked) {for (i = 0;i < ck.length; i++) { Ck[i].setattribute ("Checked" , "checked");//Change status to checked } } else {for (var i = 0;i < ck.length;i++) { ck[i]. RemoveAttribute ("checked");//Remove selected } } }</script>
2. Deleted processing page
Code:
<?php$arr = $_post["item"]; $db = new mysqli ("localhost", "root", "12345678", "Heiheihei"),//foreach ($arr as $v)//{//< c18/> $sql = "Delete from contacts WHERE id= ' {$v} '";// $db->query ($sql);/} $STR = Implode ("', '", $arr);//stitching character, $ sql = "Delete from contacts WHERE ID in (' {$str} ')";//2 ', ' 8 ', ' 4if ($db->query ($sql))//Determine if query succeeded, { header (" Location:shouye.php "); Success on Jump}?>
With foreach data transmission too slow, delete traverse a large variety, so direct judgment;