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 8476211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:07:03+00:00 2026-06-10T18:07:03+00:00

I want to have a dynamic menu that feeds from a table using php

  • 0

I want to have a dynamic menu that feeds from a table using php and mysql.

My table looks like this:

sec_id  sec_name    sec_group
1   section 1   group 1
2   section 2   group 1
3   section 3   group 2
4   section 4   group 1
5   section 5   group 3

I can do a query to get and display unique sec_group values but can’t figure out a way to include sec_name into each sec_group

//Query by unique sec_group
$qry_secs="SELECT DISTINCT sec_group FROM tbl_user_sec ORDER BY sec_id ASC";
$result_secs = mysql_query($qry_secs);

//echo values
while($row_secs = mysql_fetch_assoc($result_secs)){
 echo '<ul><li><a href="#">'.$row_secs['sec_group'].'</a></li></ul>';
}

Eventually, the HTML should like the code below.

<ul>
<li><a href="#">Group 1</a>
  <ul>
  <li><a href="#">Section 1</a></li>
  <li><a href="#">Section 2</a></li>
  <li><a href="#">Section 4</a></li>
  </ul>
</li>

<li><a href="#">Group 2</a>
  <ul>
  <li><a href="#">Section 3</a></li>
  </ul>
</li>

<li><a href="#">Group 3</a>
  <ul>
  <li><a href="#">Section 5</a></li>
  </ul>
</li>
</ul>

any ideas?

  • 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-10T18:07:04+00:00Added an answer on June 10, 2026 at 6:07 pm
    $q = mysql_query("SELECT sec_id, sec_name, sec_group FROM tbl_user_sec ORDER BY sec_id");
    
    // prepare data 
    $groups = Array();
    while($w = mysql_fetch_assoc($q)) {
      if(!isset($groups[$w['sec_group']])) $groups[$w['sec_group']] = Array();
      $groups[$w['sec_group']][] = $w;
    }
    
    // display data
    echo "<ul>";
    foreach($groups as $group_name => $sections) {
      echo '<li><a href="#">'.$group_name.'</a><ul>';
      foreach($sections as $section) {
        echo '<li><a href="#">'.$section['sec_name'].'</a>';
      }
      echo '</ul></li>';
    }
    echo "</ul>";
    

    There is another solution if you don’t care about sorting result by sec_id

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table which contains the rows that are dynamic from server side scripting(PHP)
I want to create a dynamic select input (dropdown menu) from JSON. I have
I want to create dynamic menu from Database it's mean i have Catagory is
I have a dynamic site with MySQL database and I want to create see
I want to query the datastore for Expando entities that have a certain dynamic
Hi I have a really complicated dynamic query that i want to use to
I have a menu like this: <ul id=menu> <li><a href=#home_slider id=home>Home</a></li> <li><a href=#portfolio_slider id=portfolio>Potfolio</a></li>
I have this code, this works perfect. Only i want to make this dynamic
I want to build a dynamic navigation menu that will fill in automatically based
I have an .NET 4.0 application using Caliburn.Micro. I want to create a dynamic

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.