如何解决CI_DB_mysql_result

时间:2015-03-02 12:08:01

标签: mysql codeigniter codeigniter-2

大家好,我的页面有问题我有控制器名称用户,我需要从我的函数中获取值并在另一个函数中使用它但我有问题:

消息:类CI_DB_mysql_result的对象无法转换为字符串

文件名:database / DB_active_rec.php

行号:**

我在控制器中的代码:

function view_ind()
{
    $this->load->model('user_model');
    $username = $this->session->userdata('username');
    $data['user']=$this->user_model->get_name($username);
    $place=$this->user_model->get_place($username);
    $data['results']=$this->user_model->get_all_names_info($place);     
    $data['main_content']='view_page';
    $this->load->view('include/tem',$data);     

}   

在我的模特中:

    function get_place($user)
{
    $this->db->select('place');
    $this->db->where('username',$user)->from('users');
    return  $this->db->get();

}

    function get_all_names_info($place)
{
    $this->db->select('*');
    $this->db->from('personal_info');
    $this->db->where('place =',$place);

    return $this->db->get();
}

当需要使用$ place显示错误信息而$ place未定义..我希望很快解决我的问题...谢谢

1 个答案:

答案 0 :(得分:0)

将您的功能改为

  function get_place($user)
{
    $this->db->select('place');
    $this->db->where('username',$user)->from('users');
    return  $this->db->get();

}

function get_place($user)
{

    return $this->db->get_where('user', array('username'=>$user))->row()->place;
}