I'm trying to echo a field of my database in the view, but I'm getting the error:
Message: Trying to get property of non-object
Filename: views/admin_view_report.php
Line Number: 7
When I echo the whole array, it works just fine. I can't find what's wrong.
Part of my controller:
function index(){
$this->load->model('viewreport');
$data['records']=$this->viewreport->getAllByChk();
$this->load->view('admin_view_report',$data);
}
Part of my model:
function getAllByChk(){
$q = $this->db->get('info');
if ($q->num_rows()>0){
foreach ($q->result_array() as $row)
{
$data[]=$row;
}
return $data;
}
}
The view:
<?php foreach($records as $row):?>
<?php echo $row->subject; ?>
<?php endforeach;?>
If I only print data['records']
it gives the following output
Array
(
[0] => Array
(
[id] => 1
[address] => 11/siddeshwari
[area] => sid
[lat] => 21
[lng] => 21
[subject] => hello
[problem] => lots of problem
[image] =>
[time] => 2011-08-11 23:49:29
[register_id] => 1
[category_id] => 1
[city_city_id] => 1
[status_status_id] => 0
)
[1] => Array
(
[id] => 2
[address] => 134 banani
[area] => banai
[lat] => 1223
[lng] => 2133
[subject] => not working
[problem] => yesproblem problem problem
[image] =>
[time] => 2011-08-12 01:09:44
[register_id] => 1
[category_id] => 2
[city_city_id] => 1
[status_status_id] => 0
)
)
but when I try to print the problem or subject only it gives the error.