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;