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.

    评论

报告相同问题?

悬赏问题

  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题