Sep*_*zky 7 php mysql database codeigniter
我是CodeIgniter的新手,我试过阅读CI的文档,但我仍然无法解决我的问题,也许有人可以帮我解决问题.这是我的代码:
在我的控制器中
class Registration extends CI_Controller{
    function __construct(){
        parent::__construct();
        $this->load->model('registration_model','rmod');
    }
    function ambil() {
        $gender = $this->input->post('kelamin');  
        $tinggi = $this->input->post('height'); 
        $berat  = $this->input->post('weight');
        $weight = $this->rmod->ambilBeratPria($tinggi);
        echo $weight;
    }
在我的模型中
function ambilBeratPria($tinggi) {
    $this->db->select('berat')->from('pria')->where('tinggi',$tinggi);
    $query = $this->db->get();
    return $query;           
}
我想在模型中获得我的查询结果,但是我得到这样的错误:
Message:  Object of class CI_DB_mysql_result could not be converted to string
也许这里有人可以帮我解决问题?谢谢.
您需要返回查询结果:
function ambilBeratPria($tinggi) {
     $this->db->select('berat')->from('pria')->where('tinggi',$tinggi);
     $query = $this->db->get();
     return $query->result();
}
编辑:
如果结果是单行:
function ambilBeratPria($tinggi) {
     $this->db->select('berat')->from('pria')->where('tinggi',$tinggi);
     $query = $this->db->get();
     if ($query->num_rows() > 0) {
         return $query->row()->berat;
     }
     return false;
}