This article mainly and everyone introduces the PHP bulk delete jquery operation, very good, with a tragic reference value, the need for friends can refer to, hope to help everyone.
As described below:
->->->
->->->
Create a View show.php
<?php header (' Content-type:text/html;charset=utf-8 '); $pdo =new PDO (' mysql:host=localhost;dbname=***; ', ' root ', ' root '); $pdo->exec (' Set names UTF8 '); $sql = ' SELECT ' from * * *; $info = $pdo->query ($sql)->fetchall (PDO::FETCH_ASSOC);? ><center><table border= "1" > <tr> <td>id</td> <td>title</td> <td> Content</td> </tr> <?php foreach ($info as $k = $v) {?> <tr> <td><input type= "Checkbo X "name=" box "value=" <?= $v [' id ']?> "><?= $v [' id ']?></td> <td><?= $v [' title ']? ></ td> <td><?= $v [' content ']?></td> </tr> <?php}?></table> <button> Bulk Delete </button></center><script src= ". /jquery.1.12.min.js "></script><script> $ (function () {$ (' button '). Click (function () {var ids=$ (': CheckBox '); var str= '; var count=0; for (Var i=0;i<ids.length;i++) {if (Ids.eq (i). Is (': Checked ')) {str+= ', '+ids.eq (i). Val (); count++; }} var str=str.substr (1); if (Confirm (' Are you sure you want to delete this ' +count+ ' bar data? ') {//Get ID after delete $.ajax ({type: ' Get ', url: ' admindel.php ', data:{str:str}, Success:function (res) { if (res>0) {alert (' delete succeeded '); for (Var i=ids.length-1;i>=0;i--) {if (Ids.eq (i). Is (': Checked ')) {Ids.eq (i). Parent (). Parent (). remove (); }}}})} return false; /*var box=document.getelementsbyname (' box '); var str= ""; for (Var i=0;i<box.length;i++) {if (box[i].checked==true) {str+= ', ' +box[i].value; }} var str=str.substr (1); alert (str); */}); }) </script>
Create admindel.php
<?php Header (' Content-type:text/html;charset=utf-8 '), $str =$_get[' str '; $pdo =new PDO (' mysql:host= localhost;dbname=***; ', ' root ', ' root '); $pdo->exec (' Set names UTF8 '); $sql = ' DELETE from * * * where ID in ('. $str. ') '; $res = $pdo->exec ($sql); Number of rows affected echo $res;? >