dourao1877 2016-01-02 11:37
浏览 57

要从各种表中获取信息,请获取“数组到字符串转换”错误

Sorry, If I sound so dumb on this but recently started php and Codeigniter.

On my product page I am able to print product's details except users details.

I get 'product id' reference from URL and then try to take reference from 'product id' for 'username' associated with it.

Here is the controller:

public function index() {
    $id = $this->uri->segment(3);
    //fetching item details on item page by this item id
    $data['listings'] = $this->my_listings_model->all_listings_details($id);

    //fetching username of user on item page by this item id
    $username = $this->my_listings_model->get_user_name($id);
    //fetching user details on item page by this username
    $data['user_info'] = $this->my_profile_model->get_all_details($username);
    $this->load->view('item', $data);
    }

And Model:

// Fetch Product details with the help of item id.
function all_listings_details($id){
    $this->db->select('*');
    $this->db->from('vbc_vacation_item_attri');
    $this->db->where('vbc_item_id', $id);
    $query = $this->db->get();
    $query_result = $query->result();
    return $query_result;
}

// Function to select username with the help of item id.
function get_user_name($id){
    $this->db->select('v_posting_member');
    $this->db->from('vbc_vacation_item_attri');
    $this->db->where('vbc_item_id', $id);
    $query = $this->db->get();
    $query_result = $query->result();
    return $query_result;
}

// Collect *All Details* Of A User..
function get_all_details($username){
    $this->db->select('*');
    $this->db->from('vbc_registered_members');
    $this->db->where('v_member_username', $username);
    $query = $this->db->get();
    $result = $query->result();
    return $result;
}

I have spent some good time trying to fix it but no good.

Shows error:

Message: Array to string conversion

  • 写回答

1条回答 默认 最新

  • dtja73027 2016-01-02 21:49
    关注

    Finally I got it resolved, thanks all for your efforts to help me..

    In model function

    function get_user_name($id)
    

    I just had to replace last line

    return $query_result;
    

    with

    // To get single value instead of array we have to call first row of results
    $row = $query_result[0];
    return $row->v_posting_member;
    

    And it did the trick.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料