2017-02-22 120 views
0

我的數據將有一個數字鍵,如何與另一個表進行均衡,因此可以將其稱爲名稱。我想更改數據(數字鍵)從其他表中的文本。如何在codeigniter中使用連接表獲取數據NO ID?

我的表1:

+-----------------------+ 
| ID | Name | Category | 
------------------------- 
| 1 | Home | 21 | 
| 2 | Pro | 23 | 
+-----------------------+ 

和表2:

+---------------------+ 
| ID | name_category | 
----------------------- 
| 21 | Sweet Home | 
| 23 | your Home | 
+---------------------+ 

如何得到相同的ID?但該數據會在表1所示

回答

1

嘗試像this.Use jointable1.ID = table2.ID .displays的table1所有數據與類別名稱從table2匹配上表1 category ID

$this->db->select(*) 
     ->from('table1') 
     ->join('table2', 'table1.ID = table2.ID'); 
$result = $this->db->get()->result_array(); 
print_r($result);//displays all data of table1 with category names from table2 matching on table1 category ID. 
0
$this->db->query('select table1.* from table1 inner join table2 on table1.id = table2.id'); 
$this->db->result(); 
相關問題