2016-05-31 96 views
0

我想使用连接来匹配2个表如何使用Join | codeigniter | sql |

我有表user_to_designment

而且

我有表的用户

我想匹配表上user_id(他们都有这个价值) 我尝试了多种方式来做到这一点。

现在这是我的代码:

$this->codeignitercrud->join ('join', 'user_to_designment', 'user_id' 'user_to_designment.user_id=username.user_id' ); 

但这个代码给了我一个错误。

我用笨CRUD系统:http://demo.code-abc.com/codeignitercrud/help/index.html

我希望你们能帮助我。

亲切的问候,

Sterrek

回答

0
$this->db->select('*'); 
    $this->db->from(FIRST TABLE NAME); 
    // IF Field name is common in both table use this way 
    $this->db->join_using(SECOND TABLE NAME,'FIELD NAME'); 
    //other wise 
    $this->db->join(SECOND TABLE NAME,'1st table FIELD NAME=2nd table Field name');  
    $query = $this->db->get(); 
0

能否请您使用下面的代码

$this->db->select("b.user_id); $this->db->from('username as b'); $this->db->join('user_to_designment as bo','bo.user_id=b.user_id',inner);

1
this->db->select('*'); 
    $this->db->from('A'); 
    $this->db->join('B','B.client_id=A.client_id'); 


    $result=$this->db->get(); 
    return $result->result(); 
+0

嘿感谢您的回答是:我怎么可以编辑这行我桌子? @dharmesh:$ this-> db-> join('B','B.client_id = A.client_id'); –

+0

把你的基本表名称,而不是'A'和辅助表名称,而不是'B' –