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/google-chrome/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 我想在codeigniter中加入两个表,但它不起作用_Php_Codeigniter - Fatal编程技术网

Php 我想在codeigniter中加入两个表,但它不起作用

Php 我想在codeigniter中加入两个表,但它不起作用,php,codeigniter,Php,Codeigniter,我的代码是 function admin_profile() { $this->db->select('*'); $this->db->from('bk_users as A'); $this->db->join('bk_ctoe as B', 'A.ID=B.customer_id' ); $this->db->join('bk_ctoe as C', 'A.ID=C.employee_id' ); return $

我的代码是

 function admin_profile()
{
 $this->db->select('*');
    $this->db->from('bk_users as A');
    $this->db->join('bk_ctoe as B', 'A.ID=B.customer_id' );
    $this->db->join('bk_ctoe as C', 'A.ID=C.employee_id' );
return  $this->db->get()->result();
} 
 same as
  SELECT * FROM `bk_users` as `A` JOIN `bk_ctoe` as `B` ON 
    `A`.`ID`=`B`.`customer_id` JOIN `bk_ctoe` as `C` ON 
    `A`.`ID`=`C`.`employee_id`

此查询返回空列。为了更好地理解,我还添加了图片。请提前感谢

在CI中尝试以下代码更改您的方法,如下所示。这将返回与
customer\u id
employee\u id

function admin_profile()
{
    $this->db->select('*');
    $this->db->from('bk_users as A');
    $this->db->join('bk_ctoe as B', 'A.ID=B.customer_id OR A.ID=B.employee_id' );    
    return  $this->db->get()->result();
} 

尝试使用以下代码作为示例

    $this->db->select('*');
    $this->db->from('login');
    $this->db->join('registration', 'registration.userid = login.userid');
    //$query=$this->db->get('registration');
    $this->db->where('login.status',2);
    $query=$this->db->get();
    return $query;

您是说数据是使用原始SQL正确返回的,而不是通过CodeIgniter构建查询时返回的?否则这不是一个CI问题。不,我只是说这个查询在CI中返回空字符串,当我在db中使用raq查询时,返回空冒号,而不是我想要选择的实际数据。内部联接需要引用两侧的匹配项,确保您的数据在那里。如图所示,您的
customer\u id
employee\u id
bk\u用户的
id
相同。这没有道理。确保您的
employee\u id
customer\u id
正确无误。我的表用户拥有所有用户。在customer_id中,包含用户的id,该id与员工的情况相同,我已经完成并发布了答案。谢谢你的帮助。你真好
    $this->db->select('*');
    $this->db->from('login');
    $this->db->join('registration', 'registration.userid = login.userid');
    //$query=$this->db->get('registration');
    $this->db->where('login.status',2);
    $query=$this->db->get();
    return $query;