TP3.2 实现批量操作(更改数据库多条数据的某一个字段)

1. 首先前端页面获取,选中的ID

<li><button class="button" onclick="batchDelete()" >批量确认</button></li>

<if condition="$vo.cashing_state eq 0">
<td id="productTbody"><input name="sub" id="cashing_id" type="checkbox" value="{$vo.cashing_id}"></td>
    </if>
<if condition="$vo.cashing_state neq 0">
    <td></td>
    </if>

2.js获取,ajax传输

    <script>
        //批量删除
        function batchDelete() {
            var uid= new Array();
            $("#productTbody input[type='checkbox']:checked").each(function() {
                if (!isNaN($(this).val())) {
                    uid.push($(this).val());
                }
            });
            if(uid.length ==0){
                alert("没有勾选目标或者不需要确定!");
                return false;
            }
            delete_user(uid);
        }
        function delete_user(uid){
//            alert(uid);
                $.ajax({
                    type : "post",
                    url : "{:U('master/member/delete_user')}",
                    data : { "uid" : uid.toString() },
                    dataType : "json",
                    success : function(data){
                        if(data!=0){
                            alert("操作成功!");
                            location.reload();
                        }else{
                            alert("请多选!");
                            location.reload();
                        }
                    }
                });
        }
    </script>

3.后台接受,处理

 

public function delete_user($uid){
        $uid = substr($uid,0,strlen($uid));
        $ini['cashing_id'] = array('in',$uid);
        $res = M('money_cashing')->where($ini)->setField('cashing_state',1);
//        echo M()->_sql();
        echo $res;
    }

猜你喜欢

转载自blog.csdn.net/qq_42154707/article/details/81206595