Masud Sarker Masud Sarker - 9 months ago 63
HTML Question

Echo/Print Query Result at Controller in Codeigniter

I am trying to display my Model query return result in my controller, but I don't know how to do it. could you please show me? Thanks in advance

Controller:

function updateJobsheetCDC()
{
$prnID = $this->input->post('prnID');

$this->load->model('Ipss_model');
$data['prnEmail'] = $this->Ipss_model->prnEmailList($prnID);

echo $data['prnEmail']['name'];
}


Model:

function prnEmailList($prnID)
{
$q = $this->db->query("SELECT pm.* , prm.*,e.* from principal_master pm ,principal prm,email e where pm.prnID=e.prnID and prm.prID= pm.prID and e.prnID='" .$prnID."'");

if($q->num_rows()>0) {
foreach($q ->result() as $row)
{
$data[] = $row;
}
return $data;
}
}


I have tried
echo $data['prnEmail']['name']; but it do not work. It shows Severity: Notice

Message: Undefined index: name.

Answer Source

You have multi-dimentinal array returning from model. So you have to loop over them then print data

function updateJobsheetCDC()
{
    $prnID = $this->input->post('prnID');

    $this->load->model('Ipss_model');
    $data = $this->Ipss_model->prnEmailList($prnID);
    foreach ($data as $key => $value) {
      echo $value->name; 
    }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download