PHP Bulk Delete jquery instance code

Source: Internet
Author: User
Tags php foreach
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;? >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.