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

  • SEARCH
  • Home
  • 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 8355719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:57:15+00:00 2026-06-09T09:57:15+00:00

I’m trying to build a dynamic menu (with sub menus) in Php and MySql.

  • 0

I’m trying to build a dynamic menu (with sub menus) in Php and MySql. And trying to build dynamic editor for manipulate with this menu, create , delete and etc. I’ve stacked when creating menu category with it’s position. To understand well take a look at mysql table structure =>

create table menu(
id int(5) NOT NULL AUTO_INCREMENT PRIMARY KEY,
sort_id UNSIGNED BIGINT NOT NULL,
title VARCHAR(20) NOT NULL,
etc ...);

I’m sorting menu categories with sort_id, and during creating I gave this column different values (for first time, by default) , because after creating another categories , I’m adding values by 1 and subtracting by 1 too , but I think it is pretty bad way doing it. Any ideas how to manage MySql table to define position of created categories (which would be forward or backward) ? thanks 🙂

  • 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-09T09:57:17+00:00Added an answer on June 9, 2026 at 9:57 am

    You shouldn’t use the sort_id as @Jerska said because then you won’t be able to sort your submenus & it will complicate/confuse your program logic. You can have a table like this instead

    CREATE TABLE menu(
      id INT NOT NULL AUTO_INCREMENT,
      PRIMARY KEY(id),
      parent_id INT,
      FOREIGN KEY(parent_id) REFERENCES menu(id),
      sort_id INT,
      title VARCHAR(100)
    ) ENGINE=InnoDB;
    

    if the parent_id is set to null then it is a root menu.


    This is an example menu for you:

    Home & Garden
    – Living Room
    – Dining Room
    – Bathroom
    – Bedroom
    – Garden & Conservatory
    Electricals
    – Sound & Vision
    – Computing & Phones
    – Home Appliances
    – Small Appliances

    It would be stored like this:

    INSERT INTO menu
      (parent_id, sort_id, title)
    VALUES
      (null, 1, "Home & Garden"),
      (null, 2, "Electricals"),
      (1, 1, "Living Room"),
      (1, 2, "Dining Room"),
      (1, 3, "Bathroom"),
      (1, 4, "Bedroom"),
      (1, 5, "Garden & Conservatory"),
      (2, 1, "Sound & Vision"),
      (2, 4, "Small Appliances"),
      (2, 3, "Home Appliances"),
      (2, 2, "Computing & Phones");
    

    If you actually inserted them in that order, the ID of “Home & Garden” would be 1, and the ID of “Electricals” would be 2 (don’t confuse with the sort_id) and the ID of “Living Room” would be 3, the ID of “Dining Room” would be 4… since we’re auto-incrementing on the ID field.

    So if you want to have a sub-category say in Sound & Vision, first you would find the ID, in this case it would be 8 and then you would add new records with the parent ID as 8.

    Example sub-sub-category:

    Electricals  
    - Sound & Vision  
      * Televisions  
      * Audio  
    

    You would insert these records:

    INSERT INTO menu
      (parent_id, sort_id, title)
    VALUES
      (8, 1, "Televisions"),
      (8, 2, "Audio");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.