大家好,我的页面有问题,我有 Controller 名称用户,我需要从我的函数中获取值并在另一个函数中使用它,但我有问题:
消息:类 CI_DB_mysql_result 的对象无法转换为字符串
文件名:database/DB_active_rec.php
行号:**
我在 Controller 中的代码:
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未定义..我希望尽快解决我的问题...谢谢
最佳答案
将您的功能更改为
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;
}
关于mysql - 如何解决 CI_DB_mysql_result,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28809435/