doutang6600
2017-08-17 05:00
浏览 52
已采纳

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.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douhe6181 2017-08-17 05:05
    已采纳

    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; 
        }
    }
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题