Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.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 CodeIgniter未返回与查询相同的结果_Php_Sql_Codeigniter - Fatal编程技术网

Php CodeIgniter未返回与查询相同的结果

Php CodeIgniter未返回与查询相同的结果,php,sql,codeigniter,Php,Sql,Codeigniter,我正在运行一个查询,从两个不同的表中选择数据: $this->db->select('a.any_id, a.name'); $this->db->from('table1 a, table2 b'); $this->db->where('a.any_id = b.any_id'); $this->db->where('b.other_id = "$myId"'); 如果在PHPmyAdmin中运行此查询,它将返回一些结果,但当我在CodeIgn

我正在运行一个查询,从两个不同的表中选择数据:

$this->db->select('a.any_id, a.name');
$this->db->from('table1 a, table2 b');
$this->db->where('a.any_id = b.any_id');
$this->db->where('b.other_id = "$myId"');
如果在PHPmyAdmin中运行此查询,它将返回一些结果,但当我在CodeIgniter中运行此代码时,它将返回一个空数组


有小费吗?这简直让我发疯。

我想是因为您正在尝试连接两个表,而您没有使用codeigniter
$This->db->join()
在用户指南上向下滚动以查看连接()


然后vardump它。

我想是因为您正在尝试连接两个表,而您没有使用codeigniter
$this->db->join()
在用户指南上向下滚动以查看join())


然后把它扔掉。

大家好,谢谢你们的回复

它与使用join子句无关

我刚换了衣服

$this->db->where('b.other_id = "$myId"');


而且工作得很好。还不知道为什么,因为第一行非常适合简单的查询。

大家好,谢谢您的回复

它与使用join子句无关

我刚换了衣服

$this->db->where('b.other_id = "$myId"');

而且工作得很好。还不知道为什么,因为第一行非常适合简单的查询。

试试这个

        $this->db->select('a.any_id.*,table2.name');
        $this->db->from('table1 a'); 
        $this->db->join('tabl2 b', 'a.id=b.id', 'left');
        $this->db->where('a.id',$id);      
        $query = $this->db->get();
        return $query->result(); 
试试这个

        $this->db->select('a.any_id.*,table2.name');
        $this->db->from('table1 a'); 
        $this->db->join('tabl2 b', 'a.id=b.id', 'left');
        $this->db->where('a.id',$id);      
        $query = $this->db->get();
        return $query->result(); 

$this->db->select('a.any_id,a.name')$这->数据库->来自('table1a,table2b')$这->数据库->其中('a.any\u id=b.any\u id',NULL)$this->db->where('b.other_id=“$myId””,NULL)$query=$this->db->get();返回$query->result()不,它不起作用。与之前相同的0结果和此
$This->db->select('a.any_id,a.name')$这->数据库->来自('table1a,table2b')$这->数据库->其中('a.any_id','b.any_id')$这->数据库->其中('b.other_id',$myId)$query=$this->db->get();返回$query->result()
您可能需要查看如何使用db->join()
$this->db->select('a.any_id,a.name')$这->数据库->来自('table1a,table2b')$这->数据库->其中('a.any\u id=b.any\u id',NULL)$this->db->where('b.other_id=“$myId””,NULL)$query=$this->db->get();返回$query->result()不,它不起作用。与之前相同的0结果和此
$This->db->select('a.any_id,a.name')$这->数据库->来自('table1a,table2b')$这->数据库->其中('a.any_id','b.any_id')$这->数据库->其中('b.other_id',$myId)$query=$this->db->get();返回$query->result()
您可能需要考虑使用db->join()将多个表放入FROM中,这称为交叉联接,然后如果您向WHERE子句
tablea=tableb
添加约束,它会有效地将其转换为内部联接。将多个表放入FROM中,这称为交叉联接,然后,如果您将约束添加到WHERE子句
tablea=tableb
,它将有效地将其转换为内部联接。第一个是使用初始行作为完整的WHERE,第二个是将其拆分为“this column”=此约束。两者都是有效的,尽管第一个应该像这样写:
$this->db->where('b.other_id='。$myId)第一个只是使用初始行作为完整行,其中第二个将其拆分为“this column”=此约束。两者都是有效的,尽管第一个应该像这样写:
$this->db->where('b.other_id='。$myId)