PHP对所有页面的布局相同


PHP same layout to all pages

我是web开发的新手。我想每隔一页使用此索引页布局。所以我做了这个代码。现在,当索引页面打开时,我得到了php中包含该表的完美布局。但当我点击旧书时,它被重定向到"1.php",但布局保持不变,那个表没有被替换。我现在已经附上了屏幕截图,我想在其他重定向页面中替换图书显示部分,但我不接受这个代码,请建议我编辑这个代码

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cz">
        <head>
        <style>
    ul {
        list-style-type: none;
        margin: 0;
        padding: 0;
        overflow: hidden;
        background-color: #ff3333;
    }
    li {
        float: left;
    }
    li a {
        display: block;
        color: white;
        text-align: center;
        padding: 14px 16px;
        text-decoration: none;
    }
    li a:hover {
        background-color: #ff8080;
    }
    </style>
        <style>
         body
          {
            background-image: url("back.jpg");
            background-position:0px 0px;
        background-size: cover;
            background-repeat: repeat;
          }
        </style>
        <style>
    .center {
        margin: auto;
        width: 60%;
        padding: 100px;
    }
    </style>
        </head>
        <body>
        <style>
        table{
            border-spacing:15px;
        }
        td{
            padding:30px;
        }
         body
          {
            background-image: url(back.jpg);
            background-position:0px 0px;
    background-attachment:fixed;
        background-size: cover;
            background-repeat: repeat;
          }
        </style>
        <div class="center">
         <ul>
      <li><a class="active" href="?page=home">NewBooks</a></li>
      <li><a href="index.php?con=1">OldBooks</a></li>
      <li><a href="#contact">Rent a book</a></li>
      <li><a href="#about">Feedback</a></li>
    </ul>
    <div id="RightPart">
        <?php
        $con;
     require "connect.php";
        $sql="select * from nbook";
        $row = $conn->query($sql);
        $n=0;
        echo"<form method='post'><table border='0' align='center'><tr>";
            while($arr = $row->fetch_assoc()) 
            {
                   $i=$arr['BookId'];
            if($n%3==0)
            {
            echo "<tr>";
            }
           echo "
            <td height='280' width='240' align='center'><img src='data:image/jpg;base64,".base64_encode( $arr['BookImage'] )."'height='250' width='200'><br/>
            <b>BOOKNAME:</b>".$arr['BOOKNAME']."
           <br><b>Author:</b>".$arr['Author']."
           <br><b>Publication:</b>&nbsp;".$arr['PublicatonHouse']."
           <br><b>Discount:</b>".$arr['Discount']."%
           <br><br><a href='buy.php?con=11& itemno=$i'><img src='images/MetalPlakDa5new.gif' width='70' height='20'/></a>
           <a href='index.php?con=11'><img src='images/view7.jpg' width='70' height='20'/></a>
           </td>";
          $n++;
            }


              echo "</tr></table>
               </form>";
    if($_REQUEST['con']==1)
    {
    include("1.php");
    }
    error_reporting(1);
     include("index1.php");
       ?>
       <div class="cleaner"></div>
    </div>
    <div id="Bottom">
    <p class="down"><b>Copyright &copy; VJTI BOOK SHOP by:VJTI</b></p>
    </div>
            </div>
    </div>
        </body>
        </html>

更好的是,您可以编写单独的header.php、sidebar.php和footer.php。

然后按照以下顺序将它们包含在您的每个页面中:

    <?php 
     include("header.php");
     include("sidebar.php");
     ?> 
     .............
     .............
     Here goes individual page's HTML content followed by
      ..............
     ..............
     <?php
     include("footer.php");
     ?>

要想拥有一个格式良好的页面,最好花一点时间学习简单现代的PHP模板引擎,如Twig,并像英雄一样开始你的职业生涯:)

相关文章: