繁体   English   中英

CodeIgniter 查询返回一个空数组

[英]CodeIgniter query returns an empty array

我在 CodeIgniter 中有一个 JOIN 查询,它返回一个空数组。

我的控制器部分:

if ($this->session->has_userdata('user')) {

    $id = $this->session->user['id'];

    $where = ["products.user_id =" => $id];

    $status = $this->insertModel->get_status($where);

    $this->load->view('profile', ["status" => $status]);
}

我的型号:

return $this->db
        ->from('photos')
        ->join('products', 'photos.prod_id = products.id', 'left')
        ->where($where)
        ->get()
        ->result_array();

在您的控制器中,只需发送$id而不是$where

$status = $this->insertModel->get_status($id);

并以 Codeigniter 方式在模型中重建 where 子句:

->where('products.user_id', $id)

这里查看文档

关于 MVC (模型=数据库交互,视图=浏览器输出和控制器=您的应用程序逻辑)

控制器:
你的错误在 $where,检查我的代码

if ($this->session->has_userdata('user')) {

    $id = $this->session->user['id'];

    //$where = ["products.user_id =" => $id];//old line
    $where = array("products.user_id" => $id);//new line

    $status = $this->insertModel->get_status($where);

    $this->load->view('profile', ["status" => $status]);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM