Welcome Guest, Not a member yet? Register   Sign In
How to retrieve data using multiple join case
#1

[eluser]ashutosh[/eluser]

Currently i have foreign key thirdsmcontent_id value , now i want to get the value of

`thirdsubmenu_name` from `thirdmenu` table,`submenu_name` from `submenu` table,`menu_name` from `mainmenu` table .

Please help me to solve this problem.
I tried below code but my model code is not correct. it is not display my data


Code:
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              ......


In My controller
Code:
$thirdsubmenu_id = $this->uri->segment(4);
              
       $data['main_menuname'] = $this->thirdsmcontentdetailsmodel->getMainMenuNameOfSubmenu($thirdsubmenu_id);
       $data['sub_main_menuname'] = $this->thirdsmcontentdetailsmodel->getSubMenuNameSubmenu($thirdsubmenu_id);
      $data['third_sub_main_menuname'] = $this->thirdsmcontentdetailsmodel->getThirdSubMenuNameSubmenu($thirdsubmenu_id);

In My model

Code:
//---------------------------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');
      }
        //---------------------------get Sub  Menu Name by Menu id-----------------------------------
     function getSubMenuNameSubmenu($thirdsubmenu_id)
      {    
             $this->load->database();
             $query = $this->db->join('mainmenu', 'mainmenu.mainmenu_id = submenu.mainmenu_id')->get_where('thirdsubmenu',array('thirdsubmenu_id'=>$thirdsubmenu_id));  
             return $query->row('submenu_name');
        }
        //---------------------------Get the third menu name-------------------------------------
         function getThirdSubMenuNameSubmenu($thirdsubmenu_id)
      {    
             $this->load->database();
             $query = $this->db->get_where('thirdsubmenu',array('thirdsubmenu_id'=>$thirdsubmenu_id));  
             return $query->row('thirdsubmenu_name');
        }


Getting Error:

Code:
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


Messages In This Thread
How to retrieve data using multiple join case - by El Forum - 03-29-2013, 05:49 AM
How to retrieve data using multiple join case - by El Forum - 03-29-2013, 07:26 AM
How to retrieve data using multiple join case - by El Forum - 03-29-2013, 07:34 AM
How to retrieve data using multiple join case - by El Forum - 03-29-2013, 07:42 AM
How to retrieve data using multiple join case - by El Forum - 03-29-2013, 07:59 AM
How to retrieve data using multiple join case - by El Forum - 03-29-2013, 08:09 AM
How to retrieve data using multiple join case - by El Forum - 03-29-2013, 08:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB