php批量POST修改

WBOY
リリース: 2016-06-13 11:32:01
オリジナル
818 人が閲覧しました

这是一个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>
ログイン後にコピー

服务端处理:

    <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>
ログイン後にコピー

 

 

ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のおすすめ
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート