dongweihuai5601 2016-01-14 21:46
浏览 133

用于在index.php文件中打开php页面的PHP命令

I have an index.php file. Inside the index.php file I am using the following php code to open a "home.php" page from a "pages" folder:

<?
switch (isset($do)) {
    case $do=='home':
        include("pages/home.php");
        break;
}?>

It works fine. My problem is that I want to open a "about.php" page inside the index.php as well. The "about.php" page is not inside the "pages" folder but rather in a different folder called "about". I am using this php code but it is not working:

<?
switch (isset($show)) {
case $show=='about':
    include("about/about.php");
    break;
}?>

Can someone please point where I am wrong? I appreciate your help.

  • 写回答

1条回答 默认 最新

  • douzou8074 2016-01-14 21:52
    关注

    Your switch syntax is incorrect. Try this:

    if (isset($_GET['show']))
    {
        switch ($_GET['$show'])
        {
            case 'home':
                include 'pages/home.php';
                break;
    
            case 'about':
                include 'about/about.php';
                break;
        }
    }
    

    And then use URLs like website.com/index.php?show=home or website.com/index.php?show=about.

    Your first code works but most likely by a mistake. isset($do) in switch probably returns false because $do doesn't exist. $do=='home' statement returns also false so the code in first case is executed.

    评论

报告相同问题?

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM