Coded INCLUDE Files

All pages of the eCommerce site have the same overall format and contain the same information with the exception of the specific content for the page. This commonality is achieved through three INCLUDE files that are copied into all pages. This page summarizes these files.

Page Formats

The following code reproduces the general layout of all pages and shows where and how the included files are placed in the appropriate locations on the pages.

<html>
<head>
  <title>eCommerce Site</title>
  <link href="stylesheetEC.css" rel="stylesheet">
  <?php require('jscript.inc') ?>
</head>
<body>


<div style="position:absolute; top:0px; left:0px; width:780px;
  background-color:seagreen; color:white; padding:5px">

  <?php require('header.inc') ?>

</div>


<div style="position:absolute; top:75px; left:10px; width:175px">

  <?php require('menu.inc') ?>

</div>


<div style="position:absolute; top:75px; left:200px; width:550px">

  -- main page content --

</div>


</body>
</html>

header.inc File

The header.inc file is imported into the top division of each page. The code uses in-line style specifications to produce the top banner. There is not much coding in the file, but it could be expanded to include many other features that you might wish to appear in the header of your pages.

header.inc
<span style="font-size:32pt; font-weight:bold">softWarehouse.com</span>

menu.inc File

The menu.inc file is imported into the left-most division of all pages to provide a commonly accessible search menu for locating products for sale. The complete coding for this file, whose various parts were discussed on previous pages, is shown below.

menu.inc
<a href="home.php">Home</a>
<a href="shopcart.php">Shopping Cart</a>
<br>
<br>
<span class="head4">Software Categories:</span>
<table>
<?php

//Establish data connection
		
  $conn = odbc_connect
  ('Driver={Microsoft Access Driver (*.mdb)}; DBQ=c:\inetpub\wwwroot\PHPTutorial\Ecommerce\databases\ecommerce.mdb','','');
		
//Issue SQL SELECT Statement
		
  $sql = "SELECT DISTINCT ItemType FROM Products ORDER BY ItemType";
  
//Execute the SQL Statement and create a recordset
		
  $rs = odbc_exec($conn, $sql);
  
//Loop through the recordset and display the necessary records

 while($row = odbc_fetch_array($rs)) 
	
	{
echo "<tr style=\"color:seagreen; line-height:8pt; font-size:9pt\"
			onMouseOver=\"this.style.backgroundColor='lightgreen'; 
			this.style.color='darkgreen'; this.style.cursor='hand'\"
			onMouseOut=\"this.style.backgroundColor='white'; 
			this.style.color='seagreen'\"
			
			onClick=\"location.href='search.php?Category=$row[ItemType]'\">
			
			
			<td>$row[ItemType]</td>
		</tr>";

		
		}

//Close the DB connection

odbc_close($conn);

?>
</table>

<form action="search.php" method="get">
  <span class="head4">Search for:</span><br>
  <input type="text" name="Criterion" class="textbox" size="12"
    value="<?php echo $_GET[Criterion]?>">
  <input type="submit" class="buttonS" name="Submit" value="Go"
    onMouseOver="OverMouse(this)"; onMouseOut="OutMouse(this)">
</form>

jscript.inc File

Finally, the jscript.inc file is reproduced below.

jscript.inc
<script language="javascript">
function OverMouse(button)
{
  button.style.backgroundColor="lightgreen"
  button.style.color='darkgreen'
  button.style.cursor='hand'
}
function OutMouse(button)
{
  button.style.backgroundColor="seagreen"
  button.style.color='white'
}
</script>

It is important to note that the INCLUDE files contain only the code shown here. There are no <HTML> or <BODY> tags or any other coding than what is needed for the particular purpose of the file. These files are imported into a fully tagged HTML page and you can cause display problems if you include more information than needed in the files.

With these common displays and functionalities out of the way, now, it becomes much easier to concentrate on coding the main content for each of the pages of the site.