Home > Backend Development > PHP Problem > How to batch POST modification in php

How to batch POST modification in php

coldplay.xixi
Release: 2023-03-04 14:50:02
Original
3389 people have browsed it

How to modify php batch POST: 1. Add [[]] to the name in the front-end form, and the code is [<input type="hidden" name="id[]" value="{$vo.id}">]; 2. The backend accepts [$id = $_POST [id] [$i]].

How to batch POST modification in php

How to modify php batch POST:

Add []## to the name in the front-end form #, such as:

<input type="hidden" name="id[]" value="{$vo.id}">
Copy after login

The backend accepts such as: $id = $_POST [id] [$i]; $i is the loop variable in for. When $i is the same, $_POST [id] can be made [$i] and $_POST [name] [$i] are in one-to-one correspondence;

[Related learning recommendations:

php programming (video)]

Front-end form:

对所选操作:
全选 主题 校区 房间 报修人 联系电话 报修时间 审核 报修状态
{$vo.id}<input type="hidden" name="id[]" value="{$vo.id}"> {$vo.topic} {$vo.xiaoqu} {$vo.room} {$vo.pname} {$vo.phone} {$vo.create_time|date='Y-m-d H:i:s',###}
Copy after login

Server-side processing:

    /**
     * 批量修改状态
     */
    public function updateList() {
        $result = false;
        for($i = 0; $i < count ( $_POST [id] ); $i ++) {
            
            $id = $_POST [id] [$i];
            $check = $_POST [check] [$i];
            $status = $_POST [status] [$i];
            
            // 保存登录信息
            $Repair = M ( &#39;Repair&#39; );
            $data [&#39;id&#39;] = $id;
            $data [&#39;check&#39;] = $check;
            $data [&#39;status&#39;] = $status;
            $result = $Repair->save ( $data );
        }
        
        if (false !== $result) {
            $this->success ( &#39;修改成功!&#39; );
        } else {
            $this->error ( &#39;修改失败!&#39; );
        }
    }
Copy after login

[Related learning recommendations:

Programming video]

The above is the detailed content of How to batch POST modification in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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