0

I'm wondering how to create a menu template which allows you to go into different pages in PHP? I'm an amateur to PHP and is still new to a lot of new things. I want to create something like this : https://i.stack.imgur.com/ylfe8.jpg

This is the code that I came up with for the nav bar but how to create the menu page? Thanks so much in advance.

<!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>

My code look something like this, which is in a separate php file as my 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>

With a PHP file like that, can I use a code like the following to create the menu page, how do I use it? (The code doesn't work)

   <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>
JLLo
  • 21
  • 4
  • take a look at: http://www.w3schools.com/default.asp CSS basis is what you want to organize your page – Mohamed Amjad LASRI Dec 29 '15 at 16:42
  • It sounds like the best approach is a nested foreach loop to iterate through your menu items. http://stackoverflow.com/a/26018/1427090 – ja408 Dec 29 '15 at 18:46
  • Hi @ja408, thanks for your answer but I'm still confused as to how to do it if I want it to be like an . – JLLo Jan 07 '16 at 20:53

1 Answers1

0

Which was display in your Menu. That all are the different pages of php Like For Home Page->index.php,about->about.php,Quizzes->quiz.php Then Write Like this

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

Write the HTML of that particular page.

Yagnik Detroja
  • 921
  • 1
  • 7
  • 22
  • Hi thanks for your reply but I used multidimensional arrays for all my pages which is in a single php file. How do I include all those as buttons for people to select? – JLLo Dec 29 '15 at 17:43