php - 如何创建包含链接到 PHP 中不同数组的框的内容页面?

标签 php css html nav

我想知道如何在 PHP 中创建一个允许您进入不同页面的菜单模板?我是 PHP 的业余爱好者,对很多新事物还是陌生的。我想创建这样的东西:http://i.stack.imgur.com/ylfe8.jpg

这是我为导航栏设计的代码,但是如何创建菜单页面呢?非常感谢。

<!DOCTYPE html>
<html>

    <head>
        <title>Smart Quizzes </title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <link href="css/css.css" rel="stylesheet">
                <script src= "http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <script src= "js/bootstrap.js"> </script>   
        </head>

    <body>


        <div class = "navbar navbar-inverse navbar-static-top">
            <div class = "container">
                <div class="navbar-header">
                   <a href= "nav.php" class = "navbar-brand"><img src="img/logo.jpg" width="50" height="40" border="0"> Smart Quizzes </a> 



                    <button class = "navbar-toggle" data-toggle= "collapse" data-target = ".navHeaderCollapse">
                        <span class = "icon-bar"> </span>
                        <span class = "icon-bar"> </span>
                        <span class = "icon-bar"> </span>

                    </button>

                </div>
                <div class = "collapse navbar-collapse navHeaderCollapse">

                    <ul class = "nav navbar-nav navbar-right">

                                            <li class = "active"><a href = "nav.php" About </a></li>

                        <li class = "dropdown">

                            <a href = "#" class = "dropdown-toggle" data-toggle = "dropdown">Quizzes <b class = "caret"> </b></a>
                            <ul class = "dropdown-menu">
                                <li><a href = "#">Singapore History</a></li>
                                <li><a href = "#">Basic Php</a></li>
                                <li><a href = "#">HTML/CSS/JavaScript+</a></li>
                                <li><a href = "#">Basic Math</a></li>
                            </ul>
                            <li><a href = "#"> Contact Us</a></li>                                                


                    </ul>
                </div>
            </div>
        </div>
</body>
</html>

我的代码看起来像这样,它在一个单独的 php 文件中作为我的 menu.php

`<html>

<body>
    <?php

        $quizHistoryQ = [

            "Q1" => ["questions"=>"ABC?",
                "options" => ["this is option 1",
                               "this is option 2",
                                "this is option 3"],
                "answer" =>2
        ],

           "Q2" => ["questions"=>"This is the Question String for question 2",
                "options" => ["this is option A",
                               "this is option B",
                                "this is option C"],
                "answer" =>1
        ],

               "Q3" =>["questions"=>"This is the Question String for question 3",
                "options" => ["this is option X",
                               "this is option Y",
                                "this is option Z"],
                "answer" =>0
        ]
            ];





        $quizMathQ = [ 

            "q1" => ["questions"=>"This is the Question String for question 1",

                "options" => ["this is option 1",
                               "this is option 2",
                                "this is option 3"],
                "answer" =>2
        ],

           "q2" => ["questions"=>"This is the Question String for question 2",
                "options" => ["this is option A",
                               "this is option B",
                                "this is option C"],
                "answer" =>1
        ],

               "q3" =>["questions"=>"This is the Question String for question 3",
                "options" => ["this is option X",
                               "this is option Y",
                                "this is option Z"],
                "answer" =>0
        ]
            ];



        $quizHTMLQ = [ "q1" => ["questions"=>"This is the Question String for question 1",
                "options" => ["this is option 1",
                               "this is option 2",
                                "this is option 3"],
                "answer" =>2
        ],

           "q2" => ["questions"=>"This is the Question String for question 2",
                "options" => ["this is option A",
                               "this is option B",
                                "this is option C"],
                "answer" =>1
        ],

               "q3" =>["questions"=>"This is the Question String for question 3",
                "options" => ["this is option X",
                               "this is option Y",
                                "this is option Z"],
                "answer" =>0
        ]
            ];


        $allQuizArr = [$quizHistoryQ, $quizMathQ, $quizHTMLQ];


?>
</body>
</html>

有了这样的 PHP 文件,我可以使用像下面这样的代码来创建菜单页面吗,我该如何使用它? (代码不起作用)

   <html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>


        <?php
        require_once 'getData.php';

function quizTitles($quizzes_title) {
    $output = "";
    $output = $output . '<li class =" ' . $quizzes_title["$quizHistoryQ"] . ' "> '; 
    $output = $output . '<a href=" ' . $quizzes_title["$quizMathQ"] . ' ">';
    $output = $output . '<img src=" ' . $quizzes_title["$quizHTMLQ"] . ' "> ';
    $output = $output . '</a>';
    $output = $output . '</li>';

   return $output;

}

foreach($quizTitles as $quizzes_titles) {
  echo quizTitles($quizzes_titles);
 } 

?>
    </body>
</html>

最佳答案

显示在您的菜单中。那都是php的不同页面 Like 对于首页->index.php,about->about.php,Quizzes->quiz.php 然后这样写

      <li class = "active"><a href = "about.php"> About </a></li>
      <li class = "active"><a href = "quiz.php"> Quizzes</a></li>

编写该特定页面的 HTML。

关于php - 如何创建包含链接到 PHP 中不同数组的框的内容页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34515159/

相关文章:

php - 删除MYSQL表字段中的空格

css - 让导航 div 展开整个高度

html - CSS - 浏览器窗口调整大小时图像问题

html - 无法垂直对齐 : text field with image in horizontal layout

javascript - 通过导航栏中的 anchor 链接显示/隐藏 Div

php - MySQL 查询将查找对多个用户名使用相同 IP 地址的用户

php - 如何在 mysqli 查询中仅比较 (Y-m-d)

PHP/MySQL 从列表中删除重复名称

jquery - mCustomScrollbar - 滚动条只出现在 F12 按下时(开发工具/Firebug)而不是隐藏元素/div

html - 为什么要这样做?默认填充或边距属性?