Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用不同函数的where子句的Codeigniter_Php_Codeigniter_Postgresql - Fatal编程技术网

Php 使用不同函数的where子句的Codeigniter

Php 使用不同函数的where子句的Codeigniter,php,codeigniter,postgresql,Php,Codeigniter,Postgresql,我有一个Postgres数据库,其中有一个订单表和一个订单内容表,其中包括订单的所有项目和订单id。我正在尝试查看订单历史 在我的模型中,我有两个函数,一个用于检索订单,另一个用于检索订单的所有内容,如下所示: function retrieve_orders($userID){ $query = $this->db->get('orders'); $this->db->where('user_id', $userID); return $quer

我有一个Postgres数据库,其中有一个订单表和一个订单内容表,其中包括订单的所有项目和订单id。我正在尝试查看订单历史

在我的模型中,我有两个函数,一个用于检索订单,另一个用于检索订单的所有内容,如下所示:

function retrieve_orders($userID){
    $query = $this->db->get('orders');
    $this->db->where('user_id', $userID);
    return $query->result_array();
}

function get_order_contents($orderID){
    $query = $this->db->get('order_contents');
    $this->db->where('order_id', $orderID);
    return $query->result_array();
}
因此,在我的控制器中,我调用retrieve_orders并将结果数组传递给视图。在视图中,我想为每个订单创建一个包含所有内容的HTML表。因此,我遍历每个顺序,并在循环中调用get_order_contents

一切都应该正常,但是发生的情况是源代码中显示了此错误:

错误号:

错误:列用户id不存在 第3行:其中用户_id='3' ^选择* 从订单内容 其中用户_id='3'

如您所见,出于某种原因,当我在视图中调用get_order_contents时,它使用我为retrieve_orders函数指定的where子句


到目前为止,我所做的是尝试手动停止缓存,但没有效果。非常感谢您的帮助。

在每个函数中,请尝试在获取之前放置位置

当您试图获取订单内容时,它将使用前面where中的where子句


通常的做法是,在其他调用(如where等)之后,在最后一次调用$this->db时使用get。请参阅codeigniter中的活动记录文档。

像这样链接您的db函数

return $this->db->where('user_id', $userID)
                ->get('orders')
                ->result_array();

为什么不使用$this->db->get_where

我知道这不是答案,但我认为您应该创建带有内部联接的单查询,而不是十个查询