dongtui2029 2018-10-13 12:44 采纳率: 0%
浏览 32

如何动态创建第二个下拉列表

I have successfully been able to create the start of my dynamic dropdown navigation bar. Which looks like the following:

enter image description here

The code I have that works for this is as following:

1- The function I'm calling:

function loop_array($array = array(), $parent_id = 0){
    if(!empty($array[$parent_id])){
        echo '<ul>';
            foreach($array[$parent_id] as $items){
                ?>
                    <li><a href="view.php?id=<?php echo $items['id'] ?>"><?php echo $items["title"] ?></a>
                    <?php loop_array($array, $items['id']);echo '</li>';
            }
        echo '</ul>';
    }
}

function display_menus(){
    $con = mysqli_connect("localhost", "root", "", "solvedesktop");
    $query = $con->query("SELECT * FROM pages WHERE published = 1");
    $array = array();

    if(mysqli_num_rows($query)){
        while($rows = mysqli_fetch_array($query)){
            $array[$rows['parent_id']][] = $rows;
        }
        loop_array($array);
    }
}

2- The index page:

<?php require_once(__DIR__."/../includes/config.php"); ?>
<?php require_once(__DIR__."/../includes/functions.php"); ?>
<?php require_once(__DIR__."/../includes/header.php"); ?>
        <h2 style="text-align:center;">Cork Symm Knowledgebase</h2>
                <?php display_menus(); ?>
        </div>
    <?php require_once(__DIR__."/../includes/footer.php");

The CSS I have is:

ul {
list-style:none;
padding:0px;
margin:0px;
}

ul li {
display:block;
position:relative;
float:left;
border:1px solid #2747E8;
}

li ul {
display:none;
}

ul li a {
display:block;
background:#2747E8;
padding:5px 10px 5px 10px;
text-decoration:none;
white-space:nowrap;
color:#fff;
}

ul li a:hover {
background:##2747E8;
}

li:hover ul {
display:block;
position:absolute;
}

li:hover li {
float:none;
}

li:hover a {
background:#000000;
}

li:hover li a:hover {
background:#2747E8;
}

#drop-nav li ul li {
border-top:0px;
}

I'm currently trying to add a second dropdown, for example from the image above if I hover over VMAX3 200K I should get another dropdown appear to the right of that, my issue is I have been trying to implement that into the function for the past number of hours and I have been unsuccessful thus for.

The table I have in my database is: enter image description here

The navigation system is based of the different ids from the table. For example where parent_id and child_id is equal to 0 you will appear on the main navigation page: enter image description here

For the first dropdown the parent_id will need to match one of the ids from the main navigation, for example the page VMAX 200K's parent_id will match the id of the VMAX3 and will appear in the list as shown in the top screenshot.

So the last part of this navigation, from the function I'm trying to write the code whereby a parent_id will match an id, AND the child_id will match the id of the resulting parent_id. (I hope this makes sense, it's rather confusing to say in English, and I'm finding it just as hard to write in PhP :( )

Any help with this would be gratefully appreciated.

Thanks and regards, Conal

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?