phpcodeigniteractiverecordresultset

getting the value of the single field output using the codeigniter active record


the following function is supposed to read the name of the given asset code from the database. but it triggers the error: "Trying to get property of non-object"

function sban_name($asset){
    $this->db->select('name');
    $this->db->from('asset_types');
    $this->db->where('code',$asset);
    return $this->db->get()->result()->row('name');
}

All I want is to have the name of the asset returned back to the controller.


Solution

  • Use row() like,

    return $this->db->get()->row()->name;