Ajax selection, all-in-one, anti-election, single-deletion/batch-deletion

Source: Internet
Author: User

show.php

<meta charset= "Utf-8" &GT;&LT;?PHP//Link Database$link=Mysqli_connect(' 127.0.0.1 ', ' root ', ' root ', ' mone ');//Set character setsMysqli_query($link, ' Set names UTF8 ');//Receive current page$page=Empty($_get[' page '])? 1:$_get[' Page '];//find the total number of bars$sql= "SELECT * from User";$res=Mysqli_query($link,$sql);$count=mysqli_num_rows($res);//How many bars are displayed per page$length= 3;//Find out the total number of pages$num _page=Ceil($count/$length);//Offset Amount$limit= ($page-1) *$length;//Enquiry$sql 2= "SELECT * FROM User Limit"$limit,$length";$res 2=Mysqli_query($link,$sql 2); while($a=Mysqli_fetch_assoc($res 2)){    $data[' Data '] [] =$a;}$data[' home_page '] = 1;$data[' prev_page '] =$page-1<1?1:$page-1;$data[' next_page '] =$page+1>$num _page?$num _page:$page+1;$data[' last_page '] =$num _page;?><table> <tr> <th> Select </th> <th>ID</th> <th> user name </th > <th> Password </th> <th> gender </th> <th> age </th> <th> class </ th> <th> Mobile </th> <th> edit </th> </tr> <div id= "main" > <?phpforeach($data[' Data '] as $k=$v) {?> <tr id= "<?php Echo$v[' user_id '];? > "> <td><input type=" checkbox "name=" Check "value=" <?php Echo$v[' user_id '];? > "></td> <td><?phpEcho $v[' user_id '];? ></td> <td><?phpEcho $v[' username '];? ></td> <td><?phpEcho $v[' pwd '];? ></td> <td><?phpEcho $v[' sex '];? ></td> <td><?phpEcho $v[' Age '];? ></td> <td><?phpEcho $v[' class_name '];? ></td> <td><?phpEcho $v[' phone '];?  ></td> <td> <a href= "" > Modify </a> </td> </tr> <?php} ></div></table><button onclick= "fun1 ()" > select all </button><button onclick= "fun2 ()" > All </button><button onclick= "Fun3 ()" > Reverse selection </button><button onclick= "Fun4 ()" > Single delete/batch delete </ Button><script>functionfun1 () {varCheck = Document.getelementsbyname (' Check ');  for(vari=0;i<check.length;i++){            if(check[i].checked==false) {Check[i]. checked=true; }        }    }    functionfun2 () {varCheck = Document.getelementsbyname (' Check ');  for(vari=0;i<check.length;i++){            if(check[i].checked==true) {Check[i]. checked=false; }        }    }    functionFun3 () {varCheck = Document.getelementsbyname (' Check ');  for(vari=0;i<check.length;i++){            if(check[i].checked==true) {Check[i]. checked=false; }Else{Check[i]. checked=true; }        }    }    functionFun4 () {vararr = document.getelementsbyname (' Check '); varAR = [];  for(vari=0;i<arr.length;i++){            if(arr[i].checked==true) {ar. push (Arr[i].value); }        }        varid = ar.tolocalestring (); if(id== ") {alert (' Please select an item first '); return false; }Else{            //Ajax Requests            varAjax =NewXMLHttpRequest (); Ajax. Open ("Get", "delete.php?id=" +ID); Ajax.Send (); Ajax. onreadystatechange=function(){                if(Ajax.readystate==4 && ajax.status==200){                    //alert (ajax.responsetext); Success                    if(ajax.responsetext==1){                         for(vari=0;i<ar.length;i++){                            varTr=document.getElementById (Ar[i]); TR.Remove (); }                    }                }            }        }    }</script>

delete.php

<?PHP//Receive pass Value$id=$_get[' ID '];//Link Database$link=Mysqli_connect(' 127.0.0.1 ', ' root ', ' root ', ' mone ');//Set character setsMysqli_query($link, ' Set names UTF8 ');//Stitching SQL$sql= "DELETE from the user WHERE user_id in ($id)";if(Mysqli_query($link,$sql)){    Echo1;}Else{    Echo2;}

Ajax selection, all-in-one, anti-election, single-deletion/batch-deletion

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.