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)

云罗郡主
Release: 2023-04-04 09:38:01
forward
2766 people have browsed it

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'=>'不成功']);
        }
Copy after login

(2) view

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

(3)js Note

layer插件
Copy after login
<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 = '要跳转的页面';
                        });
                    }
                }
            });
        }
    });
Copy after login

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!

Related labels:
php
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template