首页 > 解决方案 > Bootstrap 下拉 - 当 URL 中的 id 时不下拉

问题描述

我正在构建的网站遇到一个有趣的问题。当我到达一个包含 id 的 url 时,一个选项的下拉菜单停止工作。

举个例子,如果我在 http://localhost/degs/serpstudentsinclass.php?id=3,如果我点击 Admin 下拉菜单,什么也不会发生。如果我点击返回主页 http://localhost/degs/index.php,Admin 下拉菜单开始工作没问题。

在使用移动设备工作时,这也增加了一个额外的问题。一旦你到达 http://localhost/degs/serpstudentsinclass.php?id=3,你就完全失去了使用导航菜单的能力(因为现在它是一个完整的下拉菜单,由于屏幕大小)。因此,您必须再次返回 index.php,然后菜单将再次开始工作。

关于为什么会这样的任何想法?

头文件

<?php
// session file
include_once 'includes/session.php';?>
<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../css/site.css" />
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">




    <title><?php echo $title ?></title>

</head>
<body>
<div class="container">
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <a class="navbar-brand" href="index.php">DEGS</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav mr-auto">
                <li class="nav-item">
                    <a class="nav-link" href="index.php">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="serpentine.php">Serpentine</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="uturn_box.php">U-Turn Box</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="blocked_evasive.php">Blocked Evasive</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="forward_reverse.php">Forward Reverse</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="controlled_braking.php">Controlled Braking</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="cumulative_skills_day.php">Cumulative Skills - Day</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="cumulative_skills_night.php">Cumulative Skills - Night</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="evoc_challenge.php">Evoc Challenge</a>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"  data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        Admin
                    </a>
                    <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                        <a class="dropdown-item" href="users.php">Users</a>
                        <a class="dropdown-item" href="classes.php">Classes</a>
                        <a class="dropdown-item" href="students.php">Students</a>
                        <a class="dropdown-item" href="legends.php">Legend</a>
                        <a class="dropdown-item" href="tests.php">Tests</a>
                    </div>
                </li>
            </ul>
            <ul class="navbar-nav ml-auto">
                <li class="nav-item active">
                    <?php
                    if(!isset($_SESSION['userid'])){
                        ?>
                        <a class="nav-link" href="login.php">Login <span class="sr-only">(current)</span></a>
                    <?php } else { ?>
                <li class="nav-item"><a class="nav-link" href="logout.php">Logout <span class="sr-only">(current)</span></a></li>
                <?php } ?>
                </li>
            </ul>
        </div>
    </nav>

问题开始的页面 - 其他页面遵循类似的模式,您可以在其中选择班级以获取学生列表。

<?php
$title = "DEGS - Students";
require_once 'includes/header.php';
require_once 'includes/auth_check.php';
require_once 'db/conn.php';

if(!isset($_GET['id'])){
    echo 'error';
} else {
    $id = $_GET['id'];
    $results = $admin->getStudents($id);
    $class = $admin->getClassDetails($id);
    $students = $admin->getStudents($id);


}
?>
<h1>Serpentine - Class <?php echo $class['class']?></h1>

<br/>
<br/>
<table class="table">
    <tr>
        <th>Last Name</th>
        <th>First Name</th>
        <th>Agency</th>
        <th>Class</th>
        <th># of Attempts</th>
        <th>Student Operations</th>
    </tr>
    <?php while($r = $results->fetch(PDO::FETCH_ASSOC)) { ?>
        <tr>
            <td><?php echo $r['lname']?></td>
            <td><?php echo $r['fname']?></td>
            <td><?php echo $r['agency']?></td>
            <td><?php echo $class[1]?></td>
            <td><?php echo $serpentine->getAttemptCount($r['student_id']) ?></td>
            <td>
                <a href="serpview.php?id=<?php echo $r['student_id']?>" class="btn btn-primary">View Attempts</a>
                <a href="serpadd.php?id=<?php echo $r['student_id']?>" class="btn btn-success">Add Attempt</a>
            </td>
        </tr>
    <?php }?>
</table>

标签: phpbootstrap-4

解决方案


我想到了!最后我没有包括我的页脚!希望这对遇到此问题的其他人有所帮助!


推荐阅读