用户
 找回密码
 入住 CI 中国社区
搜索
查看: 989|回复: 0
收起左侧

$this->db->affected_rows();

[复制链接]
发表于 2014-4-3 15:47:11 | 显示全部楼层 |阅读模式
Model:
PHP复制代码
 
        function goods_update($data)
        {
 
            $this->db->where('goods_no', $data['goods_no']);
            $this->db->update('iwebshop_goods', $data);
            return $this->db->affected_rows();
        }
        function goods_sync_insert($data)
        {
           
            $param['goods_no'] = $data['goods_no'];
            $param['goods_name'] = $data['name'];
            $param['goods_huo'] = $data['huo_no'];
            $param['goods_price'] = $data['market_price'];
            $param['goods_unit'] = $data['unit'];
            $param['goods_scale'] = $data['scale'];
            $param['goods_update_time'] = time();
            $param['goods_update_user'] = $data['user'];
            $this->db->insert('iwebshop_sync',$param);
            return $this->db->affected_rows();
        }
 
复制代码


controllers
PHP复制代码
 
    function goods_edit_where()
    {
        $data = array(
           'goods_no' => $this->input->post('goods_no'),
           'huo_no' => $this->input->post('huo_no'),
           'name' => $this->input->post('name'),
           'market_price' => $this->input->post('market_price'),
           'unit' => $this->input->post('unit'),
           'sort' => $this->input->post('sort'),
           'station' => $this->input->post('station'),
           'is_del' => $this->input->post('is_del'),
         );
 
        $this->load->helper(array('form'));
        $this->load->library(array('session'));
        $this->load->model('goods_m');
 
        $result['urow'] = $this->goods_m->goods_update($data);
 
        $data['scale'] = $this->input->post('scale');
        $data['user'] = $this->session->userdata('aName');
        $result['irow'] = $this->goods_m->goods_sync_insert($data);
       
        echo json_encode($result);
    }
 
复制代码


View
PHP复制代码
 
jQuery.ajax({
                    type:"post",
                     url: base_path+"index.php/goods/goods_edit_where",
                     dataType:'json',
                    data: {'goods_no':goods_no,'huo_no':huo_no,'name':name,'market_price':market_price,'unit':unit,'sort':sort,'station':station,'is_del':is_del,'scale':scale},
                    success: function(data){
 
                        alert(data['urow'] );
                        alert(data['irwo']);
                        if(data['urow'] > 0 && data['irwo'] > 0)
                        {
                            jQuery(".msgerror").hide();
                            jQuery(".msgsuccess p").text("修改成功,插入成功!");
                            jQuery(".msgsuccess").fadeIn();
                        }
                        else if(data['urow'] <= 0 && data['irwo'] > 0)
                        {
                            jQuery(".msgerror").hide();
                            jQuery(".msgsuccess p").text("修改失败,插入成功!");
                            jQuery(".msgsuccess").fadeIn();
                        }
                        else if(data['urow'] > 0 && data['irwo'] <= 0)
                        {
                            jQuery(".msgerror").hide();
                            jQuery(".msgsuccess p").text("修改成功,插入失败!");
                            jQuery(".msgsuccess").fadeIn();
                        }
                        else
                        {
                            jQuery(".msgsuccess").hide();
                            jQuery(".msgerror p").text("修改失败");
                            jQuery(".msgerror").fadeIn();
                        }
                    }
                });
 
复制代码


                        alert(data['urow'] );  有值
                       alert(data['irwo']);  一直都是空 怎么回事?


本版积分规则