Try something like this:
$row = $this->db->get_where('items', array('id' => $id))->row();
Or if you just need a price:
$price = $this->db->select('cost_price') ->get_where('items', array('id' => $id)) ->row() ->cost_price;
EDIT
Your method was fine to the point, look:
$query = $this->db->query('SELECT * FROM items WHERE id="$id"'); $res = $query->result();
echo $row['cost_price']; // we have an object, not an array, so we need:
echo $row->cost_price;
Alternatively, if you want an array, you can use result_array() instead of result() .
My path, row() , returns only the first row. It is also an object, and if you need an array, you can use row_array() .
I suggest you read about everything here .
Shomz source share