#1
  1. A Change of Season
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,545
    Rep Power
    221

    Simple 2 level navigation


    Hi;

    Wanna make a simple 2 level Bootstrap nav. What is a simple query to make a 2 level nav out of this?

    Code:
    CREATE TABLE `launch_documentation` (
     `id` int(11) NOT NULL AUTO_INCREMENT,
     `parent_id` int(11) DEFAULT NULL,
     `title` varchar(100) NOT NULL,
     `description` longtext NOT NULL,
     PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2016
    Location
    Cheshire, UK
    Posts
    89
    Rep Power
    72
    Perhaps
    Code:
    SELECT a.id as aid
         , a.title as atitle
         , a.description as adescription
         , b.id as bid
         , b.title as btitle
         , b.description as bdescription
    FROM launch_documentation a
        LEFT JOIN launch_documentation b
            ON a.id = b.parent_id
    ORDER BY a.id, b.id
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2016
    Location
    Cheshire, UK
    Posts
    89
    Rep Power
    72
    P.S.
    You may want to add WHERE a.parent_id IS NULL to the above query.

IMN logo majestic logo threadwatch logo seochat tools logo