search

Home  >  Q&A  >  body text

How to implement multi-level menu in the front desk of website in PHP?

How do the front desks of most websites now implement multi-level menus? Of course, these menu data contents are controllable by the server and are in the database, rather than static on the front end

我想大声告诉你我想大声告诉你2814 days ago627

reply all(3)I'll reply

  • 天蓬老师

    天蓬老师2017-05-16 13:07:13

    1. Design a menu table with fields similar to <id, url, name, pid, status> (pid is the id of the upper-level menu, the pid of the first-level menu is 0, status is whether to display, design according to your own needs)
    2. The frontend generates an array structure based on the data in the table and renders it on the page
    3. Of course there is a backend, how to delete, modify and check the data in the table

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 13:07:13

    function select_tree($tree, $id = 0, $lev = 0,$html=[]) {
      foreach ($tree as $key => $items) {
        if ($items['parent_id'] == $id) {
          $newid = $items['id'];
          //$items['id']
          $html[$items['id']] = str_repeat("&nbsp;&nbsp;",$lev) . '└─' . $items['title'];
          $html=$html + select_tree($tree, $newid, $lev+2,$html);
        }
      }
      return $html;
    }

    reply
    0
  • 迷茫

    迷茫2017-05-16 13:07:13

    -.- It is recommended that Baidu php Infinitus classification
    php Infinitus classification

    I just found one for you to look at

    reply
    0
  • Cancelreply