目前我有外键 thirdsmcontent_id 值,现在我想获取的值
thirdsubmenu_name
从thirdmenu
表,submenu_name
从submenu
表,menu_name
从mainmenu
表。
请帮我解决这个问题。我尝试了下面的代码,但我的模型代码不正确。它不显示我的数据
我的数据库表结构
1)Table: mainmenu
---------------
mainmenu_id PK(primary key)
menu_name .....
2)Table: submenu
-------------------
submenu_id PK
mainmenu_id FK (foreign key refrences mainmenu table)
submenu_name .....
3)Table: thirdsubmenu
--------------------
thirdsubmenu_id PK
submenu_id FK (foreign key refrences submenu table)
thirdsubmenu_name ........
4)Table: thirdsmcontentdetails
--------------------
thirdsmcontent_id PK
thirdsubmenu_id FK (foreign key refrences thirdsubmenu table)
content ......
在我的控制器中
$thirdsubmenu_id = $this->uri->segment(4);
$data['main_menuname'] = $this->thirdsmcontentdetailsmodel->getMainMenuNameOfSubmenu($thirdsubmenu_id);
在我的模型中
//---------------------------get Main Menu Name by Menu id-----------------------------------
function getMainMenuNameOfSubmenu($thirdsubmenu_id)
{
$this->load->database();
$query = $this->db->join('thirdsubmenu','thirdsubmenu.submenu_id = thirdsmcontentdetails.submenu_id')->get_where('thirdsubmenu',array('thirdsubmenu_id'=>$thirdsubmenu_id));
return $query->row('menu_name');
}
得到错误:
A Database Error Occurred
Error Number: 1066
Not unique table/alias: 'thirdsubmenu'
SELECT * FROM (`thirdsubmenu`) JOIN `thirdsubmenu` ON `thirdsubmenu`.`submenu_id` = `thirdsmcontentdetails`.`submenu_id` WHERE `thirdsubmenu_id` = '1'
Filename: D:\xampp\htdocs\system\database\DB_driver.php
Line Number: 330