Home > Backend Development > PHP Tutorial > PHP batch POST modification_PHP tutorial

PHP batch POST modification_PHP tutorial

WBOY
Release: 2016-07-20 11:16:18
Original
945 people have browsed it

This is a case of batch modification in thinkphp:

If you need to delete multiple records, or modify multiple records at the same time

Front-end form:

<span <</span><span form </span><span name</span><span ="form1"</span><span  method</span><span ="post"</span><span  action</span><span ="__GROUP__/Repair/updateList"</span><span ></span><span 
  对所选操作:</span><span <</span><span input </span><span type</span><span ="submit"</span><span  value</span><span ="保 存"</span><span  class</span><span ="btn btn-primary"</span><span ></span> <span <</span><span br</span><span ></span>
            <span <</span><span table </span><span id</span><span ="checkList"</span><span  class</span><span ="list table table-hover"</span><span ></span>
                <span <</span><span tr</span><span ></span>
                    <span <</span><span th </span><span scope</span><span ="col"</span><span ><</span><span input </span><span id</span><span ="check"</span><span  type</span><span ="checkbox"</span><span 
                        onclick</span><span ="checkAll()"</span> <span /></span> 全选<span </</span><span th</span><span ></span>
                    <span <</span><span th </span><span scope</span><span ="col"</span><span ></span>主题<span </</span><span th</span><span ></span>
                    <span <</span><span th </span><span scope</span><span ="col"</span><span ></span>校区<span </</span><span th</span><span ></span>
                    <span <</span><span th </span><span scope</span><span ="col"</span><span ></span>房间<span </</span><span th</span><span ></span>
                    <span <</span><span th </span><span scope</span><span ="col"</span><span ></span>报修人<span </</span><span th</span><span ></span>
                    <span <</span><span th </span><span scope</span><span ="col"</span><span ></span>联系电话<span </</span><span th</span><span ></span>
                    <span <</span><span th </span><span scope</span><span ="col"</span><span ></span>报修时间<span </</span><span th</span><span ></span>
                    <span <</span><span th </span><span scope</span><span ="col"</span><span ></span>审核<span </</span><span th</span><span ></span>
                    <span <</span><span th </span><span scope</span><span ="col"</span><span ></span>报修状态<span </</span><span th</span><span ></span>
                <span </</span><span tr</span><span ></span>
                <span <</span><span volist </span><span name</span><span ="list"</span><span  id</span><span ="vo"</span><span ></span>
                <span <</span><span tr</span><span ></span>
                    <span <</span><span td</span><span ><</span><span input </span><span type</span><span ="checkbox"</span><span  name</span><span ="key"</span><span  value</span><span ="{$vo.id}"</span><span ></span>{$vo.id}<span <</span><span input </span><span type</span><span ="hidden"</span><span  name</span><span ="id[]"</span><span  value</span><span ="{$vo.id}"</span><span ></</span><span td</span><span ></span>
                    <span <</span><span td</span><span ></span>{$vo.topic}<span </</span><span td</span><span ></span>
                    <span <</span><span td</span><span ></span>{$vo.xiaoqu}<span </</span><span td</span><span ></span>
                    <span <</span><span td</span><span ></span>{$vo.room}<span </</span><span td</span><span ></span>
                    <span <</span><span td</span><span ></span>{$vo.pname}<span </</span><span td</span><span ></span>
                    <span <</span><span td</span><span ></span>{$vo.phone}<span </</span><span td</span><span ></span>
                    <span <</span><span td</span><span ></span>{$vo.create_time|date='Y-m-d H:i:s',###}<span </</span><span td</span><span ></span>
                    <span <</span><span td</span><span ><</span><span select </span><span name</span><span ="check[]"</span><span ><</span><span switch </span><span name</span><span ="vo.check"</span><span ></span>
                            <span <</span><span case </span><span value</span><span ="0"</span><span ></span>
                            <span <</span><span option </span><span value</span><span ="0"</span><span  selected</span><span ="selected"</span><span ></span>未审核<span </</span><span option</span><span ></span>
                            <span <</span><span option </span><span value</span><span ="1"</span><span ></span>审核<span </</span><span option</span><span ></span>
                            <span </</span><span case</span><span ></span> <span <</span><span default </span><span /></span>
                            <span <</span><span option </span><span value</span><span ="0"</span><span ></span>未审核<span </</span><span option</span><span ></span>
                            <span <</span><span option </span><span value</span><span ="1"</span><span  selected</span><span ="selected"</span><span ></span>审核<span </</span><span option</span><span ></span>
                            <span </</span><span switch</span><span ></</span><span select</span><span ></</span><span td</span><span ></span>
                    <span <</span><span td</span><span ><</span><span select </span><span name</span><span ="status[]"</span><span ><</span><span switch </span><span name</span><span ="vo.status"</span><span ></span>
                            <span <</span><span case </span><span value</span><span ="已修"</span><span ></span>
                            <span <</span><span option </span><span value</span><span ="未修"</span><span ></span>未修<span </</span><span option</span><span ></span>
                            <span <</span><span option </span><span value</span><span ="任务已下"</span><span ></span>任务已下<span </</span><span option</span><span ></span>
                            <span <</span><span option </span><span value</span><span ="已修"</span><span  selected</span><span ="selected"</span><span ></span>已修<span </</span><span option</span><span ></span>
                            <span </</span><span case</span><span ></span> <span <</span><span case </span><span value</span><span ="任务已下"</span><span ></span>
                            <span <</span><span option </span><span value</span><span ="未修"</span><span ></span>未修<span </</span><span option</span><span ></span>
                            <span <</span><span option </span><span value</span><span ="任务已下"</span><span  selected</span><span ="selected"</span><span ></span>任务已下<span </</span><span option</span><span ></span>
                            <span <</span><span option </span><span value</span><span ="已修"</span><span ></span>已修<span </</span><span option</span><span ></span>
                            <span </</span><span case</span><span ></span> <span <</span><span default </span><span /></span>
                            <span <</span><span option </span><span value</span><span ="未修"</span><span  selected</span><span ="selected"</span><span ></span>未修<span </</span><span option</span><span ></span>
                            <span <</span><span option </span><span value</span><span ="任务已下"</span><span ></span>任务已下<span </</span><span option</span><span ></span>
                            <span <</span><span option </span><span value</span><span ="已修"</span><span ></span>已修<span </</span><span option</span><span ></span>
                            <span </</span><span switch</span><span ></</span><span select</span><span ></</span><span td</span><span ></span>
                <span </</span><span tr</span><span ></span>
                <span </</span><span volist</span><span ></span>
            <span </</span><span table</span><span ></span>
        <span </</span><span form</span><span ></span>
Copy after login

Server-side processing:

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440117.htmlTechArticleThis is a case of batch modification in thinkphp: If you need to delete multiple items, or modify multiple records at the same time, the front end Form: Select all theme campus rooms and contact number of the person who requested the repair...
Related labels:
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