Home > php教程 > php手册 > body text

php批量POST修改

WBOY
Release: 2016-06-13 11:32:01
Original
818 people have browsed it

这是一个thinkphp中的批量修改的案例:

 如需要删除多项,或者同时修改多项记录

前端表单:

<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

服务端处理:

    <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

 

 

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template