drpkcwwav20524605 2019-07-04 12:08
浏览 444
已采纳

使用导航栏进行Php导航

I'm trying to make an "asp.net site.Master" functional page with PHP using URL params to show or hide content in the page but it looks like only one of the params is working.

Code here:

<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>System</title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
    </head>

    <body>
        <nav class="navbar navbar-expand-lg navbar-dark bg-dark sticky-top">
            <a runat="server" class="navbar-brand" href="~/Default">LOGO</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarText">
                <ul class="nav navbar-nav">
                    <li><a class="nav-link" href="index.php?index=one">one</a></li>
                    <li><a class="nav-link" href="index.php?index=two">two</a></li>
                </ul>
            </div>
        </nav>

        <?php $mypage = isset($_GET['index']);

        switch ($mypage) {
            case "one":
                @include("./one.php");
                break;

            case "two":
                @include("./two.php");
                break;
        }
        ?>
    </body>
</html>

Doesn't matter which option I click on the navbar because it always shows me the "one" option.

Pages "one" and "two" are just an empty html with "one" and "two"

I'm sorry if I'm not as descriptive as it should, it's my first time asking here.

Thx!

  • 写回答

1条回答 默认 最新

  • doulieyu0881 2019-07-04 12:16
    关注

    The issue is here:

    $mypage = isset($_GET['index']);

    You just check if $_GET contains a field "index".

    $mypage = isset($_GET["index"]) ? $_GET["index"] : "one";
    

    This will use the given site and fall back to page one when the index is not given in the GET parameter.

    Further, try to avoid the error control operator @.

    $mypage = isset($_GET['index']) ? $_GET["index"] : "one";
    
        switch($mypage)
        {
        case "one":
            include("./one.php");
            break;
    
        case "two":
            include("./two.php");
            break;
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?