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.
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.incmenu.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
<?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>jscript.inc File
Finally, the jscript.inc file is reproduced below.
jscript.incIt 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.