Home >Backend Development >PHP Tutorial >PHP gets the data in the database table to be deleted, inserts it into a new table and then deletes the data (code)

PHP gets the data in the database table to be deleted, inserts it into a new table and then deletes the data (code)

云罗郡主
云罗郡主forward
2018-10-12 09:54:522769browse

The content of this article is about PHP getting the data in the database table to be deleted, inserting it into a new table and then deleting the data (code). It has certain reference value. Friends in need can refer to it. I hope It will help you.

1, For routing I use get

(1) Controller

 public function a(Request $request){
        //获取指定的id
        $id = $request->id;
        $rs=R::find($id);
        //仓库中
        $re=$rs->rfid;
        //判断仓库中的是否与数据库的rf在线的是否相等
        $ws= G::where('rfid','=',$re)->first();
        if($ws){
            return response()->json(['status'=>0,'msg'=>'不成功']);
        }
        //导入数据
        $sql=DB::insert("insert into gs( g ,id,created_at,updated_at) values (?,?,?,?)",
            [$rs->p,$rs->r,$rs->creat,$rs->up]);
//        成功删除
        if($sql){
            $rs->delete();
            return ['status'=>1,'msg'=>'成功'];
        }else{
            return response()->json(['status'=>0,'msg'=>'不成功']);
        }

(2) view

<span class="change" data-id="{{id}}" >关联</span>

(3)js Note

layer插件
<script>
    $(".change").click(function () {
        var id = $(this).data("id");
        if(confirm("确定xxx")){
            $.ajax({
                url: '/',
                type: 'get',
                data: {'id':id},
                success: function (res) {
                    if (res.status == 0) {
                        layer.msg(res.msg);
                    } else {
                        layer.msg(res.msg, {icon: 1}, function () {
                            location.href = '要跳转的页面';
                        });
                    }
                }
            });
        }
    });

The above is the complete introduction to PHP to get the data in the database table to be deleted, insert it into a new table and then delete the data (code). If you want to know more about php programming from entry to master full set of video tutorials , please pay attention to the PHP Chinese website.

The above is the detailed content of PHP gets the data in the database table to be deleted, inserts it into a new table and then deletes the data (code). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete