tp5 的单个删除和批量删除

不多说了直接上代码:

页面html:




    
    
    
    
    数据删除


    
  • 姓名
  • eamil
  • 问题
  • 时间
  • 操作删除
{volist name='lis' id='v' length="30"}
  • {$v.name}
  • {$v.email}
  • {$v.comment}
  • {$v.date|substr=###,0,10}
  • 删除
{/volist}

样式css:

/* show页面样式 */
.sh_dv{width: 100%;height: 100%;min-width: 320px;text-align: center;background: #f9f9f9;}
.sh_dv_tay{width: 1300px;height: 100%;margin: auto;border: 10px solid #00CC99;}
.dv_select{}
.input_sb{margin:8px;border-radius: 8px;}
.input_sel{width:300px;height:18px;padding:5px 10px;outline: none;border: 1px solid #ababab;}
.input_btn{width:50px;height:28px;color:#fff;background: #007aff;outline: none;border:none;}
.input_btn:hover{opacity: 0.8;cursor: pointer;}
.sh_dv_contact{width: 100%;height: 100%;}
.sh_ul{display: flex;}
.sh_li{line-height: 1.5;font-size: 16px;margin: 2px;border: 1px solid #8D8D8D;}
.sh_li_name{width: 150px;}
.sh_li_email{width: 250px;}
.sh_li_contact{width: 650px;}
.sh_li_time{width: 150px;position: relative;}
.sh_li_del{width:100px;}
.del{color:red;cursor: pointer;}
.del:hover{opacity: 0.8;}
.delAll{color:red;cursor: pointer;}
.delAll:hover{opacity: 0.8;}
.sh_li_tibtn{cursor: pointer;}
.time_border{width:10px;height:1px;background: #888;position: absolute;}
/*反*/
.the .time_left{transform: rotate(45deg);top:13px;right:30px;}
.the .time_right{transform: rotate(-45deg);top:13px;right:23px;}
/*正*/
.is .time_left{transform: rotate(-45deg);top:10px;right:30px;}
.is .time_right{transform: rotate(45deg);top:10px;right:23px;}

后端方法:

//条件查询    空值查询
 public function show( $inp = null,$val=null){
        if($inp =='sel'){
            $lis = Db::query("SELECT * FROM msg_information WHERE name = '$val' OR email ='$val' OR date LIKE '$val%'");//查询数据
            $this->assign('lis', $lis);
        }
        if($inp == null || $val == null){
            $lis = Db::query('select * from msg_information ORDER BY date DESC');//查询数据
            $this->assign('lis', $lis);
        }
        return $this->fetch();
    }


//删除单个
    public function del($id){
        $msg = json_encode(['msg'=>'success']);
        $msg2 = json_encode(['msg'=>'false']);
        $list = Db::query('select id from msg_information ');//查询数据
        $locar = array();
        foreach($list as $k =>$v){
            array_push($locar,$v['id']);//本地id集合
        }
        if(!empty($id) && in_array($id,$locar)){//判断传入id不为空 传入id 要在本地id集合中存在
            Db::table('msg_information')->delete($id);//查询数据
            return $msg;
        }else{
            return $msg2;
        }
        return $msg2;
    }

//批量删除
public function delAll(){
   if(request() -> isAjax()){
       $datas = $_POST['id'];
       if(!empty($datas)){
          Db::table('msg_information') -> delete($datas);//批量删除数据
          return json_encode(['msg' => 'success']);
       }else{
          return 'null';
       }
   }
   return json_encode(['msg' => 'false']);
}

作为参考,感谢前人的文章:https://blog.csdn.net/wy123123000/article/details/73571763

https://blog.csdn.net/cheeso/article/details/79125675

你可能感兴趣的:(php,web前端,js,html)