Search code examples
phpframeworkscodeigniter-2

cant display the data from controller


My problem is that I can't get data in database but if I use var_dump() I have data. This is the error:

A PHP Error was encountered Severity: Notice Message: Undefined index: projectid Filename: views/accounting_status.php Line Number: 46

This is my View

This page was accesed incorrectly.

<div class="well">
<p><h1><?=$p['projectid']?></h1></p>
<p><?=$p['code']?></p></div>

This is my Controller

function id($projectid){
    $data['p'] = $this->Accounting_Model->get_awardedid($projectid);
    //echo "<pre>".print_r($data)."</pre>";
    $this->load->view('tmp_header');
    $this->load->view('accounting_status',$data);
}

This is my Model

function get_awardedid($projectid){
    $this->db->select('*')->from('projects')
                          ->join('customer', 'projects.customerid = customer.customerid')
                          ->join('employees', 'projects.endorse_by = employees.employeeid')
                          ->where(array('acctg'=>1,'projectid'=>$projectid))
                          ->order_by('datecreated', 'desc');
    $query = $this->db->get();
    return $query->result_array();
}

Solution

  • If the result will be a single row then change on model as follows:

    function get_awardedid($projectid){
        $this->db->select('*')->from('projects')
                              ->join('customer', 'projects.customerid = customer.customerid')
                              ->join('employees', 'projects.endorse_by = employees.employeeid')
                              ->where(array('acctg'=>1,'projectid'=>$projectid))
                              ->order_by('datecreated', 'desc');
        $query = $this->db->get();
        return $query->row_array();
    }