从CodeIgniter中的数据库中检索值不起作用

时间:2014-01-23 07:37:54

标签: php mysql codeigniter

在我的Codeigniter项目中,表值不是从数据库中检索的。使用MySQL(WAMP)作为数据库。使用选择查询我已经检查了数据库中的数据并且它在那里很好。当更新它同样也检索旧值在db.But中检索后期阶段的值(即取旧账单)时,它没有检索到该值。问题仅发生在单个字段(即actual_price)。如何解决此错误。这是附加屏幕截图和控制器代码。

Retrieved value from db Value in db 控制器代码

    function bill_view($billid)
    {
        if(!$billid) {
        redirect('report/bill_report');
        }   
        $salecode   =str_replace("_","/",$billid);
        $filter ="gm_sale.saleCode ='$salecode'";   
        $billArray  =$this->sale_model->getBillinfo($filter);

        $exshowroom='';
        $bank   ='';
        $scheme='';
        $wcoNo  ='';
        $saleId =0;
        foreach($billArray as $key=>$val) {
        $exshowroom = $val['actual_price'];
        $date   =$val['saledate'];
        $sale_to=$val['saleCustomer'];
        $saleUserId=$val['saleUserId'];
        $wcoNo  = $val['wcoNo'];
        $saleId= $val['saleId'];
        if(!is_null($val['bank']) && !empty($val['bank'])){
        $bank    =$val['bank'];
        }
        if(!is_null($val['scheme_id']) && !empty($val['scheme_id'])){

          $array_scheme = unserialize($val['scheme_id']);
                ///////////////////////////////////////////
                foreach ($array_scheme as $val_scheme_id) {
                        $res_scheme = $this->db->get_where("gm_scheme",array('id'=>(int)$val_scheme_id));
                        if($res_scheme->num_rows >0){
                            $arrscheme      = $res_scheme->row_array();
                            if(!empty($scheme)) {
                            $scheme .= ",";
                            }
                        $scheme     .= $arrscheme['schemeName'];
                        }
                }
                /////////////////////////////////////////////
        }
        break;
        }

        $query  = $this->db->get_where('gm_users',array('userId'=>(int)$saleUserId));
            if($query->num_rows >0) {
            $arrUser    =$query->row_array();
            }else{
                $arrUser    =array();
            }

        $data['list_product']   =   $billArray;

        $data['exshowroom']=$exshowroom;
        $data['userinfo']   =$arrUser;  
        $data['saleCode']   =$salecode;
        $data['sale_to']    =$sale_to;
        $data['added_date'] =$date;
        $data['bank']   =$bank;
        $data['scheme'] =$scheme;
        $data['wcoNo']  =$wcoNo;
        $data['saleId'] =$saleId;
        $this->load->view('header_login');
        $this->load->view('report/bill_view',$data);
        //print_r($billArray);
        $this->load->view('footer_login');
    }

型号代码

function getBillinfo($filter=''){
           $this->db->select('*,gm_sale.added_date as saledate');
            $this->db->from('gm_sale',FALSE);
            $this->db->join('gm_products',"gm_sale.productId=gm_products.productId",FALSE);
            $this->db->join('gm_model',"gm_products.model_id=gm_model.id",FALSE);
            $this->db->join('gm_banks',"gm_sale.bank_id=gm_banks.bank_id","LEFT");
            if($filter<>"")
            $this->db->where($filter,'',FALSE);
            $this->db->order_by('gm_sale.saleId',"desc");
            $query = $this->db->get();
            print_r($query);
                if($query->num_rows>0) {
                $arrRow =$query->result_array();
                print_r($arrRow);
                return($arrRow);
            }
            return(array());
        }

1 个答案:

答案 0 :(得分:2)

您在控制器中执行数据库操作的代码应该在模型中。

控制器没有上下文

$this->db

修改你的连接(第3个参数)以检索actual_price中的值