Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8181961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:41:59+00:00 2026-06-07T00:41:59+00:00

There are two table s : one is the master and one the detail

  • 0

There are two tables : one is the master and one the detail ( foreign key ). In the master table there is a hierarchy structure : each master row has its parent hierarchy ( self-foreign key ). Perhaps the DML of the tables can explain it clearly :

CREATE TABLE classe_menu (                          
               class_menu_code int(10) NOT NULL auto_increment,  
               class_menu_lib varchar(50) default NULL,          
               class_menu_comment text,                          
               class_menu_deleted tinyint(1) default '0',        
               class_menu_ordre int(11) default NULL,            
               class_menu_parent int(10) default NULL,           
               PRIMARY KEY  (class_menu_code) ,                                                                                   
               KEY association_108_fk (class_menu_parent),                                                                 
               CONSTRAINT fk_association_108 FOREIGN KEY (class_menu_parent) REFERENCES classe_menu (class_menu_code)                   
             ) ENGINE=InnoDB DEFAULT CHARSET=latin1

CREATE TABLE menu (                                                                                           
          menu_code int(10) NOT NULL auto_increment,                                                                  
          class_menu_code int(10) default NULL,                                                                       
          menu_lib varchar(100) default NULL,                                                                         
          menu_url varchar(255) default NULL,                                                                         
          menu_titre varchar(100) default NULL,                                                                       
          menu_parent decimal(10,0) default NULL,                                                                     
          menu_visible tinyint(1) default NULL,                                                                       
          menu_ordre decimal(2,0) default NULL,                                                                       
          menu_action varchar(50) default NULL,                                                                       
          menu_icone_img varchar(255) default NULL,                                                                   
          menu_icone_flag tinyint(1) default '0',                                                                     
          menu_icone_title varchar(50) default NULL,                                                                  
          menu_deleted tinyint(1) default '0',                                                                        
          menu_tooltip varchar(25) default NULL,                                                                      
          menu_trace text,                                                                                            
          menu_image varchar(255) default NULL,                                                                       
          menu_contextuel tinyint(1) default '0',                                                                     
          menu_logo varchar(255) default NULL,                                                                        
          menu_display int(1) default '0',                                                                            
          PRIMARY KEY  (menu_code),                                                                                   
          KEY association_109_fk (class_menu_code),                                                                 
          CONSTRAINT fk_association_109 FOREIGN KEY (class_menu_code) REFERENCES classe_menu (class_menu_code)  
        ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='liste des menus du site'

As you can see ‘classe_menu’ is the master table and ‘menu’ is the detail table ; but inside the master table ‘classe_menu’ there is also a hierarchy structure implemented by the ‘class_menu_parent’ column : a ‘classe_menu’ row is a root of the hierarchy if its ‘class_menu_parent’ is NULL.

Now what I want is to get all ‘classe_menu’ root rows and the ‘menu’ rows for all ‘classe_menu’ , that is for all root ‘classe_menu’ and all of its children.

How to do that ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:42:00+00:00Added an answer on June 7, 2026 at 12:42 am
    function getMenuChildren($code,$code_is_class_menu=false){
        $children = array();
        $sql = 'SELECT * FROM menu WHERE '.($code_is_class_menu?'class_menu_code':'menu_parent').' = '.$code;
        $res = mysql_query($sql);
        while ($row = mysql_fetch_assoc($res)){
            $row['children'] = getMenuChildren($row['menu_code']);
            $children[] = $row;
        }
        return $children;
    }
    
    $class_menus = array();
    $sql = 'SELECT * FROM classe_menu WHERE class_menu_parent IS NULL';
    $res = mysql_query($sql);
    while ($row = mysql_fetch_assoc($res)){
        $row['children'] = getMenuChildren($row['class_menu_code'],true);
        $class_menus[] = $row;
    }
    
    print_r($class_menus);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my html page, I have one table, for every row there are two
There are two tables. One is users info users, one is comments info comments.
Say, there are two tables. One contains a field with long text values (for
I have two product tables Product1 and Product2. There is a one 2 one
There are two tables Table 1 select * from manage_tcp; +----+----------+--------+ | id |
There are two tables Table A id column_a 01 abc 01 abc 02 abc
There are two tables: CREATE TABLE STORE ( ID INTEGER NOT NULL, MEDICINE_ID INTEGER
My application has one table called 'events' and each event has approx 30 standard
When one table has 2 columns which refer same master table with ActiveRecord on
Recently, one of our clients has deleted two million rows from a table. Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.