【问题标题】:My Bootstrap is not working, trying to include Mysql dropdown我的 Bootstrap 不工作,试图包含 Mysql 下拉菜单
【发布时间】:2019-11-10 12:26:36
【问题描述】:

我正在尝试将 Bootstrap 应用于动态下拉菜单。

我的代码无法匹配所有其他不是 Mysql 的菜单项 落下。 Here 就是这个样子。

我的代码:

<li class = 'dropdown'>
    <a href = '#' class = 'glyphicon glyphicon-book' >
        <span class = 'caret'></span>
    </a>

    <select 
    onChange="window.location.href=this.value" class = 'dropdown-toggle' 
    data-toggle = 'dropdown'  >
        <ul class = 'dropdown-menu'>
            <option>Training </option>

<?php                                           

     $sql = "SELECT * FROM sessions where event_type = 'training' ORDER BY 
    pro_title ";

   $res = mysqli_query($con1, $sql);

   if(mysqli_num_rows($res) > 0)                                         
   {                                                 
       while($row = mysqli_fetch_array($res))                                        
       {                                         
           echo "<li><option value='mail/success.php?idx={$row['event_id']}'>{$row['pro_title']}</option></li>";                                         
       }                                 
    }
?>
        </ul>           
    </select>                               
<li>

【问题讨论】:

  • 请正确编辑您的问题。
  • echo "
  • "; ... 为什么是“
  • ”标签?
  • 谢谢,因为其他非mysql的菜单都是这样的:
  • 标签: php html twitter-bootstrap


    【解决方案1】:

    <select>Native Form Widgets - DropDown Content

    然而,在 Bootstrap 中,DropDowns 是使用 div 元素或列表创建的。

    根据您当前的代码,我假设您使用的是 Bootstrap 3.x

    这是一个你可以尝试的例子:

    <li class="dropdown">
        <a href="#" class="glyphicon glyphicon-book dropdown-toggle" data-toggle="dropdown" role="button">
            Training <span class='caret'></span>
        </a>
    
        <ul class="dropdown-menu">
            <?php
    
            $sql = "SELECT * FROM sessions where event_type = 'training' ORDER BY pro_title ";
    
            $res = mysqli_query($con1, $sql);
    
            if (mysqli_num_rows($res) > 0) {
                while ($row = mysqli_fetch_array($res)) {
                    echo "<li><a href='mail/success.php?idx={$row['event_id']}'>{$row['pro_title']}</a></li>";
                }
            }
            ?>
        </ul>
    <li>
    

    要了解有关结构的更多信息,我建议您查看以下链接 (Bootstrap 3.x):

    更新

    &lt;select onChange="window.location.href=this.value"&gt; does the same as if you would click on the links in the dropdown &lt;a href="somelink"&gt;text&lt;/a&gt;

    尽管如此,您可以在单击项目时这样做:

    试试这个代码来回显列表项:

    echo "<li><a onclick='window.location.href=\"mail/success.php?idx={$row['event_id']}\">{$row['pro_title']}</a></li>";
    

    【讨论】:

    • 非常感谢,但菜单现在没有触发 success.php?idx 有 onChange="window.location.href=this.value" 缺少我的东西 :-) 无论如何都要包括那个?非常感谢你。埃德-
    • 我在帖子中添加了更新部分。请检查一下。
    • 谢谢 Attila,它现在工作正常,除非我在下拉列表中选择 Tarining#1,我得到结果,admin/sessions.php?idx=1 在同一页面上(admin/ session.php?idx=1),我单击下拉菜单以选择另一个项目,但下拉菜单没有响应...我必须总是去家里,因为结尾没有 ?idx网址,有什么想法吗?非常感谢@Attila。
    • 更新:它现在突然工作了 :-) 有趣!谢谢大家在这里的帮助..谢谢@Attila。
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签