Article From:https://www.cnblogs.com/hopelooking/p/9215565.html

show.php

<meta charset="utf-8">
<?php
//Linked database
$link = mysqli_connect('127.0.0.1','root','root','mone');
//Set the character set
mysqli_query($link,'set names utf8');


//Receive the current page
$page = empty($_GET['page'])?1:$_GET['page'];
//Find the number of the total
$sql = "select * from user";
$res = mysqli_query($link,$sql);
$count = mysqli_num_rows($res);
//pagesize
$length = 3;
//Find the total number of pages
$num_page = ceil($count/$length);
//Offset
$limit = ($page-1)*$length;
//query
$sql2 = "select * from user limit $limit,$length";
$res2 = mysqli_query($link,$sql2);
while($a=mysqli_fetch_assoc($res2)){
    $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> username < /th>< th> cipher ≪ /th>< th> sex < /th>< th> age < /th>< th> class < /Th>< th> cell phone < /th>< th> edited < /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><?php echo $v['user_id'];?></td>
        <td><?php echo $v['username'];?></td>
        <td><?php echo $v['pwd'];?></td>
        <td><?php echo $v['sex'];?></td>
        <td><?php echo $v['age'];?></td>
        <td><?php echo $v['class_name'];?></td>
        <td><?php echo $v['phone'];?></td>
        <td>
            <a href="">Modify < /a>< /td>< /tr><? PHP}? >< /div>< /table>≪ button onclick= "fun1 ()" > all elected < /button>< button onclick= "fun2 ()" > do not select < /button>&lT; button onclick= "fun3 ()" "> reverse < /button>< button onclick= "FUN4 ()" > single deletion / batch deletion < /button>≪ script>function fun1(){
        var check = document.getElementsByName('check');
        for(var i=0;i<check.length;i++){
            if(check[i].checked==false){
                check[i].checked=true;
            }
        }
    }

    function fun2(){
        var check = document.getElementsByName('check');
        for(var i=0;i<check.length;i++){
            if(check[i].checked==true){
                check[i].checked=false;
            }
        }
    }

    function fun3(){
        var check = document.getElementsByName('check');
        for(var i=0;i<check.length;i++){
            if(check[i].checked==true){
                check[i].checked=false;
            }else{
                check[i].checked=true;
            }
        }
    }

    function fun4(){
        var arr = document.getElementsByName('check');
        var ar = [];
        for(var i=0;i<arr.length;i++){
            if(arr[i].checked==true){
                ar.push(arr[i].value);
            }
        }

        var id = ar.toLocaleString();
        if(id==''){
            alert('Please choose one 'first'.);
            return false;
        }else{
            //ajaxrequest
            var ajax = new XMLHttpRequest();
            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(var i=0;i<ar.length;i++){
                            var tr=document.getElementById(ar[i]);
                            tr.remove();
                        }

                    }
                }
            }
        }
    }
</script>

 

 

delete.php

<?php
//Receive transmission value
$id = $_GET['id'];
//Linked database
$link = mysqli_connect('127.0.0.1','root','root','mone');
//Set the character set
mysqli_query($link,'set names utf8');
//Splicing SQL
$sql = "DELETE FROM user WHERE user_id in ($id)";
if(mysqli_query($link,$sql)){
    echo 1;
}else{
    echo 2;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *