从模型返回类型的代码点火器


Codeigniter on return type from model

嗨,我想寻求帮助,以获取模型中Codeigniter中的方法,所以我只想让我的方法在给定其"country_name"的情况下从数据库中的"国家"表中返回"country_id",但我找不到正确的解决方案。例如,返回country_id

下面是不返回country_id值的代码:

public function get_country_id($cname){
    $this->db->select('country_id');
    $this->db->where('country_name',$cname);
    $d=$this->db->get('countries');
    $d=$d->result();
    return $d->country_id;
}

从查询结果获取$row。然后可以返回$rowcountry_id属性。例:

public function get_country_id($cname){
    $this->db->select('country_id');
    $this->db->where('country_name',$cname);
    $d = $this->db->get('countries');
    $row = $d->row();
    return $row->country_id;
}