How to assign the different php files

来源:互联网 发布:red flag linux 编辑:程序博客网 时间:2024/06/05 18:17

Okay, in this part, I just create a PHP demo and set them in different file.

1. index.php

<html>
<head>
<title>PHP Demo</title>
<link rel="stylesheet" type="text/css" href="site.css" />
</head>
<body>
<?php include ("header.php");?>
<div id="main">
<h1>Welcome to Xuegang Wang's Website</h1>
<h2>Web site Main Ingredients</h2>
<p>A Home Page(index.php)</p>
<p>A style sheet(site.css)</p>
<p>Include Files(Header.php, Footer.php)</p>
<?php 
include ("footer.php"); 
?>
</div>
</body>
</html>

//This file shows the basic frame of the html file. And we use include expression to conclude the footer.php file. which can show a paragraph in the included file.


2. footer.php

<p>
&copy;<?php echo date("Y");?>Wang Xuegang All Rights Reserved.
</p>


3. About.php

<html>
<head>
<title>About</title>
<link rel="stylesheet" href="site.css" />
</head>
<body>
<?php include ("header.php");?>
<div id="main">
<h1>About Us</h1>
<p>Wang Xuegang Xuegang Xuegang Xuegang Xuegang Xuegang Xuegang</p>
</div>
</body>
</html>

4. header.php

<ul id="menu">
<li><a href="Index.php">Home</a></li>
<li><a href="customers.php">Customers</a></li>
<li><a href="About.php">About</a></li>
</ul>

5. customers.php

<html>
<head>
<link rel="stylesheet" href="site.css"/>
<title>Customer Information</title>
</head>
<body>
<?php include ("header.php");?>
<div id="main">
<h1>Customer</h1>
<?php 
$conn=mysqli_connect("localhost", "root", "ganggang123", "test");
if (mysqli_connect_errno()){
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  //select_db("test");
  $sql="select distinct first_Name, last_Name from students";
  $result = mysqli_query($conn, $sql);
  echo "<table border='1'>";
  while($row=mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>".$row['first_Name']."</td>";
  echo "<td>".$row['last_Name']."</td>";
  echo "</tr>";
  }
  mysqli_close($conn);
?>
</div>
<?php 
include("footer.php");
?>
</body>
</html>

//this file, we just implement query database and show them in the webpages.

6. site.css file

@CHARSET "UTF-8";
body{
font:"Trebuchet MS", Verdana, sans-serif;
background-color:#5c87b2;
color:#696969;
}
#main{
padding:30px;
background-color:#ffffff;
border-radius:0 0 4px 4px;
}


h1{
font:Georgia, serif;
border-bottom:3px solid #cc9900;
color:#996600;
}


ul#menu{
padding:0px;
position:relative;
margin:0;
}
ul#menu li{
display:inline;
}
ul#menu li a{
background-color: #ffffff;
padding: 10px 20px;
text-decoration: none;
line-height: 2.8em;
color: #034af3;
border-radius: 4px 4px 0 0;
}
ul#menu li a:hover{
background-color:#e8eef4;
}

Every website should be better have one style file. this can help design the pages very clearly.

Okay, when you know this, you can know how to develop a website in different ways.