【发布时间】:2014-03-12 14:23:28
【问题描述】:
我的模型页面中有此代码:
public function getAll($researcherpk){
$this->db->select('*');
$this->db->from('research');
$this->db->join('researcher', 'researcher = lastname');
$this->db->where('researcherpk', $researcherpk);
return $this->db->get()->row_array();
但是当我在我的视图页面上使用它时
Age: <?php echo $data['age'];?> // this work
<?php foreach ($data as $v){ ?> //this has an error
<tr>
<td><?php echo $v->title?></td>
<td><?php echo $v->track_records?></td>
</tr>
<?php } ?>
我得到错误:
Message: Trying to get property of non-object
在我的控制器页面中:
public function researcher($researcherpk){
$this->load->model('ResearchModel');
$result['data'] = $this->ResearchModel->getAll($researcherpk);
$this->load->view('researcher',$result);
}
您认为这里的问题是什么?我的替代解决方案或更改是什么?
【问题讨论】:
-
对不起,我该怎么做 var_dump($data);?
-
没关系,我发现错了!检查我的答案:)
标签: php codeigniter