我的数据将有一个数字键,该数字键如何与另一个表相等,因此可以称为名称。我想将数据(数字键)更改为其他表格中的文本。
我的桌子1:
+-----------------------+
| ID | Name | Category |
-------------------------
| 1 | Home | 21 |
| 2 | Pro | 23 |
+-----------------------+
和表2:
+---------------------+
| ID | name_category |
-----------------------
| 21 | Sweet Home |
| 23 | your Home |
+---------------------+
如何获得相同的ID?但数据将显示在表1中
最佳答案
尝试这样。在join
上使用table1.ID = table2.ID
。显示与表1 table1
上匹配的table2
类别名称的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.
关于php - 如何在codeigniter中使用联接表获取数据NO ID?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42395589/