Possible Duplicate:
echoing in the view page
i'm trying to echo i field from my table. But the following error is showing when i run the code
Message: Trying to get property of non-object
Filename: views/details_view.php
Line Number: 6
the function of my controller
function inde开发者_StackOverflowx()
{
//using model
$data['list'] = $this->Rfetch_model->getdata();
$this->load->view('Rfetch_view', $data);
}
function get_by_id($id = 0){
$data['info'] = $this->Rfetch_model->getdata_by_id($id);
$this->load->view('details_view', $data);
}
the function of my model
function getdata () {
$this->db->select ('subject, id, problem'); // field name
$sql = $this->db->get('info'); // table name
if ($sql->num_rows () >0) {
foreach($sql->result() as $row) {
$data[$row->id] = $row->subject;
}
return $data;
}
}
function getdata_by_id($id = 0){
$this->db->where('id',$id);
$sql = $this->db->get('info');
return $sql->result();
}
}
my view (details_view):
<?php echo $info->problem; ?>
when i print the info.it gives the following output
Array
(
[0] => stdClass Object
(
[id] => 2
[address] => some
[area] => some
[lat] => 1223
[lng] => 2133
[subject] => some
[problem] =>problem
[image] =>
[time] => 2011-08-12 01:09:44
[register_id] => 1
[category_id] => 2
[city_city_id] => 1
[status_status_id] => 0
)
)
Try this:
<?php echo $info[0]->problem; ?>
In getdata_by_id
, you are returning $sql->result()
. This gives an array of objects. You can use $sql->row()
to return you an object of just that row.
精彩评论