2017-02-22 6 views
0

私のデータは、名前と呼ばれるように別のテーブルとどのように等しくするかを示す数字キーがあります。私は他のテーブルからのテキストへのデータ(数字キー)を変更したい。codeigniterにjoinテーブルを使ってNO IDを取得する方法は?

私TABLE1:

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

及び表2:同じIDを取得する方法を

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

?。しかし、データが

答えて

1

1は、TABLE1 category IDtable2マッチングからカテゴリ名とtable1.ID = table2.ID .displaysにthis.Use joinようtable1のすべてのデータを試してみてください表に表示されます。

$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(); 
関連する問題