how to create dynamic menu with sub-menu with php & mysql

后端 未结 2 1700
慢半拍i
慢半拍i 2021-01-07 05:37

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   g         


        
2条回答
  •  北海茫月
    2021-01-07 05:52

    $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 "";
    

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

提交回复
热议问题