0

In my Codeigniter project ,table value is not retrieving from database.Am using MySQL (WAMP) as database.Using Select Query i have checked the data in database and its fine there.When updating the same also its retrieving the old value in db.But when retrieving the value in later stage (ie,taking old bill) its not retrieving the value.The problem is happening only on the single field(ie,actual_price).How to solve this error.Here am attaching the screenshot and controller code for the same.

Retrieved value from db Value in db Controller Code

    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');
    }

Model Code

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());
        }
3
  • what is FALSE in join statement? Commented Jan 23, 2014 at 7:59
  • @kumar_v..If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. Commented Jan 23, 2014 at 8:12
  • The third parameter of join() expects a string to describe the type of JOIN to implement. The fourth parameter dictates the disabling of auto-quoting identifiers. These errors in implementation may or may not be problematic. We don't have a schema or sample data to test with. In the absense of a minimal reproducible example, it is too difficult to identify a correct answer. The accepted answer is misleading about accessing db in the controller and is vague about what is necessary to resolve the problem. Commented Oct 19 at 22:49

1 Answer 1

2

Your code that you have in the controller doing DB stuff should be in the model.

The controller does not have context to

$this->db

modify your joins (3rd param) to retrieve values in actual_price

Sign up to request clarification or add additional context in comments.

8 Comments

$billArray=$this->sale_model->getBillinfo($filter);No Change the same issue
is sale_model an actual mode and getBillinfo the above method in your post? have you loaded the sale_model in your controller? any errors?
The Model sale_model is already there.I have pasted the model code in the controller To check whether the db is getting data or not.Its already loaded by default .This was a running project.For maintenance purpose, i recently added one extra filed that is "actual_price",that field is not retrieving.Other field are working fine
what is the query that gets executed? try printing this using $this->db->last_query() after the query executes ($this->db->get())
$query = $this->db->get(); echo $this->db->last_query();
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.