Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在$content母版页上显示PHP页面_Php - Fatal编程技术网

在$content母版页上显示PHP页面

在$content母版页上显示PHP页面,php,Php,我想就我现在面临的问题寻求帮助。 我有一个母版页(master.php),其中包含以下代码 <html> <head> <meta charset="UTF-8"> <title>Master Page</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/cs

我想就我现在面临的问题寻求帮助。 我有一个母版页(master.php),其中包含以下代码

<html>
    <head>
        <meta charset="UTF-8">
        <title>Master Page</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">

        <!-- jQuery library -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

        <!-- Popper JS -->
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>

        <!-- Latest compiled JavaScript -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
    </head>
    <body>
        <!--Header -->
        <div class="jumbotron text-center" style="margin-bottom:0">
            <h3>Kiribati Infrastructure Database System</h3>
        </div>
        <!--Main Menu -->

        <!--Main Content -->
            <div><?php echo $content;?></div>
        <!--Footer -->        
        <div class="jumbotron text-center" style="margin-bottom:0">
            <p>Footer</p>
        </div>
    </body>
</html>

母版页
基里巴斯基础设施数据库系统
页脚

每个php页面都有以下php代码

 <?php
         $content = '';
    include('master.php');
    ?>

我现在面临的问题是无法显示其他php页面 加入那个变量

例如,我想显示此编码的结果并将其放入 $content变量,但我不知道如何使用。我将感谢为这个项目提供的任何帮助

    <body>
            <div class="container">
                            <h2>Gender Report:</h2>
                            <p></p>            
                            <table class="table">
                              <thead>
                                <tr>
                                  <th>ID</th>
                                  <th>Gender</th>
                                </tr>
                              </thead>
                              <tbody>


            <?php
            // Provide the file for username, password and database name
             require_once 'mysqlconn.php';
              $conn = new mysqli($hostname, $username, $password, $database);

              if ($conn->connect_error) {
                  die("Connection failed:" . $conn->connect_error);
              }

              $sql = "SELECT * FROM tbl_gender";
              $result = $conn->query($sql);
                       if ($result->num_rows > 0) {
                  while ($row = $result->fetch_assoc()) 
                  {

                      echo "<tr>";
                      echo "<td>" . $row['gender_id'] . "</td>";
                      echo "<td>" . $row['gender_description'] . "</td>";
                      echo "</tr>";
                  }
              } else {
                  echo "0 results";
              }
              $conn->close();
              //include('master.php');
            ?>
                              </tbody>
                            </table>
            </div>                
   </body>

性别报告:

身份证件 性别
您可以使用输出缓冲来捕获变量中php脚本的内容。通过打开输出缓冲来启动“内容”文件,通过关闭输出缓冲并将缓冲区的内容分配给变量来结束文件

<?php ob_start(); ?>

--php script which generate html content here--

<?php $content = ob_get_clean(); ?>

--在这里生成html内容的php脚本--

在上面的最后一段代码中删除正文,将其另存为php文件,并将其包含在希望显示的页面中。