1. <i id='0sn7X'><tr id='0sn7X'><dt id='0sn7X'><q id='0sn7X'><span id='0sn7X'><b id='0sn7X'><form id='0sn7X'><ins id='0sn7X'></ins><ul id='0sn7X'></ul><sub id='0sn7X'></sub></form><legend id='0sn7X'></legend><bdo id='0sn7X'><pre id='0sn7X'><center id='0sn7X'></center></pre></bdo></b><th id='0sn7X'></th></span></q></dt></tr></i><div id='0sn7X'><tfoot id='0sn7X'></tfoot><dl id='0sn7X'><fieldset id='0sn7X'></fieldset></dl></div>

        <legend id='0sn7X'><style id='0sn7X'><dir id='0sn7X'><q id='0sn7X'></q></dir></style></legend>
          <bdo id='0sn7X'></bdo><ul id='0sn7X'></ul>
        <tfoot id='0sn7X'></tfoot>

        <small id='0sn7X'></small><noframes id='0sn7X'>

      1. 帮助 PHP 递归导航列表菜单

        Help with PHP recursive navigation list menu(帮助 PHP 递归导航列表菜单)

          • <i id='ECGkP'><tr id='ECGkP'><dt id='ECGkP'><q id='ECGkP'><span id='ECGkP'><b id='ECGkP'><form id='ECGkP'><ins id='ECGkP'></ins><ul id='ECGkP'></ul><sub id='ECGkP'></sub></form><legend id='ECGkP'></legend><bdo id='ECGkP'><pre id='ECGkP'><center id='ECGkP'></center></pre></bdo></b><th id='ECGkP'></th></span></q></dt></tr></i><div id='ECGkP'><tfoot id='ECGkP'></tfoot><dl id='ECGkP'><fieldset id='ECGkP'></fieldset></dl></div>
            <tfoot id='ECGkP'></tfoot>

                <bdo id='ECGkP'></bdo><ul id='ECGkP'></ul>
                  <tbody id='ECGkP'></tbody>
              • <legend id='ECGkP'><style id='ECGkP'><dir id='ECGkP'><q id='ECGkP'></q></dir></style></legend>

                  <small id='ECGkP'></small><noframes id='ECGkP'>

                1. 本文介绍了帮助 PHP 递归导航列表菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将动态递归导航列表菜单添加到正在处理的网站.场景是菜单有 2 个由 parentid(preid) 关联的级别.

                  I am trying to add a dynamic recursive navigation list menu to a site of am working on. The scenerio is that the menu has 2 levels related by a parentid(preid).

                  我的问题是我可以正确显示第一级列表,但是我无法正确显示第二级.我不确定在哪里添加第二级的 UL 和/UL 标签.

                  My issue is that I can display the 1st level list correctly, however I cannot get the second level to display properly. I am not sure where to add the UL and /UL tags for the second level.

                  这就是我所追求的

                  <ul>
                  <li>Item 1</li>
                  <li>item 2</li>
                  <li>item 3</li>
                  <ul>
                    <li>sub item 1</li>
                    <li>sub item 2</li>
                  </ul>
                  <li>Item 4</li>
                  <li>item 5</li>
                  <ul>
                    <li>sub item 1</li>
                    <li>sub item 2</li>
                  </ul>
                  <li>item 6</li>
                  </ul>
                  

                  这实际上是我通过以下代码得到的:

                  This is actually what i am getting with the below code:

                      <ul>
                    <li>item 1
                      <ul>
                      </ul>
                    </li>
                    <li>item 2
                      <ul>
                        <li>sub item 1</li>
                        <ul>
                        </ul>
                        <li>sub item 2</li>
                        <ul>
                        </ul>
                      </ul>
                    </li>
                    <li>Sports Injuries
                      <ul>
                      </ul>
                    </li>
                      </ul>
                    </li>
                  </ul>
                  

                  下面是我用来创建菜单的类文件:

                  Below is the class file I am using to create the menu:

                  class Dynamic_Menu 
                      {
                          function getConfig()
                          {
                              $this->DB_SERVER = 'localhost';
                              $this->DB_USER = '***';
                              $this->DB_PASS = '***';
                              $this->DB_NAME = '***';
                  
                          }
                  
                          function __construct()
                          {
                              $this->getConfig();
                              $Conn = mysql_connect($this->DB_SERVER, $this->DB_USER, $this->DB_PASS);
                              if (!$Conn)
                                  die("Error: ".mysql_errno($Conn).":- ".mysql_error($Conn));
                              $DB_select = mysql_select_db($this->DB_NAME, $Conn);
                              if (!$DB_select)
                                  die("Error: ".mysql_errno($Conn).":- ".mysql_error($Conn));
                          }
                  
                          function select_row($sql)
                          {
                              //echo $sql . "<br />";
                              if ($sql!="")
                              {
                                  $result = mysql_query($sql) or die("Error: ".mysql_errno().":- ".mysql_error());
                                  if ($result)
                                  {
                                      while($row = mysql_fetch_array($result))
                                          $data[] = $row;
                                  }
                                  return $data;
                              }
                          }
                  
                          function recordCount($sql)
                          {
                              if ($sql!="")
                              {
                                  $result = mysql_query($sql) or die("Error: ".mysql_errno().":- ".mysql_error());
                                  if ($result)
                                  {
                                      $cnt = mysql_num_rows($result);
                                      return $cnt;
                                  }
                              }
                          }
                  
                          function getChild($id)
                          {
                              $menu = "";
                              $str = "";
                              $s = "SELECT * FROM vcms_sys_explorer WHERE preid = '$id' ";
                              $res = $this->select_row($s);
                              $menu .= '<ul>';
                              for ($i=0;$i<count($res);$i++)
                              {
                                  $cnt_of_child = $this->recordCount("SELECT * FROM vcms_sys_explorer where preid = '".$res[$i][eid]."' ");
                                  //if ($cnt_of_child > 0)
                                  //  $str = '';
                                  //else
                                  //  $str = " (is sub menu item)";
                  
                                  $menu .= '<li>'. $res[$i][name].$str.'</li>';   
                                  $menu .= $this->getChild($res[$i][eid]);
                              }
                              $menu .= '</ul>';       
                              return $menu;
                          }
                  
                          function getMenu($parentid)
                          {
                              $menu = "";
                              $s = "SELECT * FROM vcms_sys_explorer WHERE preid = '$parentid'  ";
                              $res = $this->select_row($s);
                  
                              $menu .= '<ul>';
                  
                              for ($i=0;$i<count($res);$i++)
                              { 
                                  $menu .= '<li>'.$res[$i][name].$this->getChild($res[$i][eid]).'</li>';
                                  if ((count($res) - 1) > $i) {
                                  }
                              } 
                  
                              $menu .= '</ul>';
                  
                              return $menu;
                          }
                      }
                  

                  我调用菜单:

                  $menu = new Dynamic_Menu();
                  $menu->getMenu(1);
                  

                  有人可以帮忙解释一下我需要在哪里放置 2 级 UL 和/UL 标签.在过去的两天里,我一直在用这个来敲打我的头.任何帮助将不胜感激,谢谢...

                  Could someone please help and explain where I need to place the level 2 UL and /UL tags. I have been banging my head with this for the last 2 days. Any help would be greatly appreciated, thanks...

                  推荐答案

                  在嵌套列表中,子列表将始终包含在 列表元素中——这就是它们嵌套的原因.您可以使用这种格式在一个函数中打印完整列表(在通用代码中,但您应该了解基本概念):

                  In a nested list, sub-lists will always be contained within a list element-- that's what makes them nested. You can print a full list in just one function using this format (in generic code, but you should get the basic idea):

                  function get_list($parent) {
                      $children = query('SELECT * FROM table WHERE parent_id = '.$parent);
                      $items = array();
                      while($row = fetch_assoc($children)) {
                          $items[] = '<li>'.$row['name'].get_list($row['id']).'</li>';
                      }
                      if(count($items)) {
                          return '<ul>'.implode('', $items).'</ul>';
                      } else {
                          return '';
                      }
                  }
                  

                  这将为您提供一个结构正确的列表:

                  And this will give you a list structured properly as:

                  <ul>
                      <li>Item 1</li>
                      <li>Item 2
                          <ul>
                              <li>Item 2.1</li>
                              <li>Item 2.2</li>
                          </ul>
                      </li>
                  </ul>
                  

                  这篇关于帮助 PHP 递归导航列表菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <legend id='rUhfJ'><style id='rUhfJ'><dir id='rUhfJ'><q id='rUhfJ'></q></dir></style></legend>

                      <tbody id='rUhfJ'></tbody>
                    • <bdo id='rUhfJ'></bdo><ul id='rUhfJ'></ul>

                          <small id='rUhfJ'></small><noframes id='rUhfJ'>

                            <i id='rUhfJ'><tr id='rUhfJ'><dt id='rUhfJ'><q id='rUhfJ'><span id='rUhfJ'><b id='rUhfJ'><form id='rUhfJ'><ins id='rUhfJ'></ins><ul id='rUhfJ'></ul><sub id='rUhfJ'></sub></form><legend id='rUhfJ'></legend><bdo id='rUhfJ'><pre id='rUhfJ'><center id='rUhfJ'></center></pre></bdo></b><th id='rUhfJ'></th></span></q></dt></tr></i><div id='rUhfJ'><tfoot id='rUhfJ'></tfoot><dl id='rUhfJ'><fieldset id='rUhfJ'></fieldset></dl></div>
                            <tfoot id='rUhfJ'></tfoot>