$this->db->from('posts');
$this->db->where('id',$this->uri->segment(3));
$data['query'] = $this->db->get();
I am trying to get one post using a where statement. I don't get any errors when I run this code. But in my view when I try to get $query->result()->body PHP gives me an error Trying to get property of non-object. So I ran print_r($query) and this is what it gave me:
(
[conn_id] => Resource id #27
[result_id] => Resource id #32
[result_array] => Array
(
)
[result_object] => Array
(
)
[custom_result_object] => Array
(
)
[current_row] => 0
[num_rows] => 0
[row_data] =>
)
I have no idea why it won't get my specific post from the database. I know my database is in working condition. I use it elsewhere in my site. I also use $this->db->where() elsewhere on my site and it works perfect. I've also tried plugging in id's of posts instead of $this->uri->segment(3) and I get the same problem. What am I doing wrong?
$this->uri->segment(3)(url parameters). Any data that a model method requires should be passed to it (usually by the controller method which calls the model). It looks like you should be usingget_where()ActiveRecord method call for your task. If you want to return a single record as an object ornullif there is no row -- userow(). For an flat array, you can userow_array().