HOME and CODE

Site Home
LAMP Home
PHP & MySQL Home
secure.php
nav.php
notes.php
Download Tutorial

DATABASE

Create Database
Drop Database
Re-Create All

TABLE

Create Table
Drop Table
Add Record
Update Record
Delete Record
Search
View all Records

MORE PHP

PHP Console Apps
PHP Web Apps

PHP and MySQL - nav.php

Code for the Navigation Table and Page Source Listings

<!-- nav.php -->

<?php // ===============================================================
      function nav($url, $text)
      {
        // IF THE URL IS THE CURRENT PAGE ...
        if (strcmp($url, basename($_SERVER['PHP_SELF'])) == 0)
        { 
          // PASSIVE TABLE CELL
          echo "<tr><td class=\"nofill\" bgcolor=\"#0000ff\">".
               "<font color=\"white\"><strong>$text</strong></font></td></tr>\n";
        }
        else
        {
          // ACTIVE TABLE CELL WITH HYPERLINK
          echo "<tr><td class=\"nofill\" bgcolor=\"#0000ff\" ".
               "onMouseOver=\"this.bgColor='#ff0000'\" ".
	       "onMouseOut=\"this.bgColor='#0000ff'\"><a href=\""
	       . $url . 
	       "\"><font color=\"yellow\">$text</font></a></td></tr>\n";
        }
      }
      // ---------------------------------------------------------------
      function nul($text)
      {
        // PASSIVE TABLE CELL
        echo "<tr><td class=\"nofill\" bgcolor=\"#0000ff\">".
             "<font color=\"white\"><strong>$text</strong></font></td></tr>\n";
      }
      // ---------------------------------------------------------------

      // ===============================================================
      // ===== This function displays the HTML and PHP code on the =====
      // ===== web page specified in $fileName                     =====
      // ===============================================================
      function dump_page($fileName)  
      {
        $fp = fopen($fileName, "r");    // ========================== ?>
    
        <table cellpadding="10" cellspacing="0" border="1">
        <tr>
        <td>
        <h3>&lt;!-- <?php echo $fileName; ?> --></h3>
        </td>
        </tr>
        <tr>
        <td>
	
        <?php // =======================================================
        echo "<pre>";
        while (!feof($fp))
        {
          $in = fgets($fp, 4094);
          echo htmlspecialchars($in);
        }
 
        fclose ($fp);    // ========================================= ?>
    
        </pre>
        </td>
        </tr>
        </table>
	
        <?php // =======================================================
  }
  // ===================================================================

  // ===================================================================
  // ===== NAVIGATION TABLE ============================================
  // ===================================================================
  require "../secure.php";    // Contains host, username and password
	
  $link = mysql_connect($host,        // Host name
                        $user,        // User name 
                        $password)    // User password
          or die("<h5>Could not connect: </h5>" . mysql_error()); ?>
	
  <table cellpadding="0" cellspacing="0" border="0" width="100%">
  <a href="../index.php"><img src="logo.PNG" width="64" height="63" border="0"></a>
  <p><strong>HOME and CODE</strong></p>
  <?php 
        nav('../../index.php', 'Site Home');
        nav('../index.php',    'LAMP Home');
        nav('index.php',       'PHP&nbsp;&amp;&nbsp;MySQL&nbsp;Home');
        nav('secureish.php',   'secure.php');	
        nav('navCode.php',     'nav.php');
        nav('notes.php',       'notes.php');
        nav('phpMySQL.zip',    'Download&nbsp;Tutorial'); ?>
  </table>

  <?php
  if (mysql_select_db ($database))
  {
    // DATABASE EXISTS =============================================== ?>
    <p><strong>DATABASE</strong></p>
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <?php nul('Create Database');
          nav('dropDB.php', 'Drop Database');
          nav('cleanUp.php', 'Re-Create All'); ?>
    </table>
    <?php // ===========================================================
    // Test if the table exists ...
    $exists = mysql_query("SELECT 1 FROM customer LIMIT 0", $link);
    if ($exists)
    {
      // TABLE EXISTS
      // Count the rows / records in the table.
      $getrows = mysql_query("SELECT * FROM customer") or die(mysql_error());
      $numrows = mysql_num_rows($getrows);
      if ($numrows > 0)
      {
        // TABLE CONTAINS DATA ====================================== ?>
        <p><strong>TABLE</strong></p>
        <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <?php nul('Create Table');
	      nav('dropTable.php', 'Drop Table');
	      nav('addData.php', 'Add Record');
	      nav('updateData.php', 'Update Record');
	      nav('deleteData.php', 'Delete Record');
	      nav('search.php', 'Search');
	      nav('viewData.php', 'View all Records'); ?>
        </table>
        <?php // ====================================================
      }
      else
      {
        // TABLE IS EMPTY =========================================== ?>
        <p><strong>TABLE</strong></p>
        <table cellpadding="0" cellspacing="0" border="0" width="100%">
	<?php nul('Create Table');
	      nav('dropTable.php', 'Drop Table');
	      nav('addData.php', 'Add Record');
	      nul('Update Record');
	      nul('Delete Record');
	      nul('Search');
	      nul('View all Records'); ?>
        </table>
        <?php // ====================================================
      }	
    }
    else
    {
      // TABLE DOES NOT EXIST ======================================= ?>
      <p><strong>TABLE</strong></p>
      <table cellpadding="0" cellspacing="0" border="0" width="100%">
      <?php nav('createTable.php', 'Create Table');
            nul('Drop Table');
            nul('Add Record');
            nul('Update Record');
            nul('Delete Record');
            nul('Search');
            nul('View all Records'); ?>
      </table>
      <?php // ======================================================
    }
  }
  else
  {
    // DATABASE DOES NOT EXIST ====================================== ?>
    <p><strong>DATABASE</strong></p>
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <?php nav('create.php', 'Create Database');
          nul('Drop Database');
	  nav('cleanUp.php', 'Re-Create All'); ?>
    </table>
    <p><strong>TABLE</strong></p>
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <?php nul('Create Table');
          nul('Drop Table');
          nul('Add Record');
          nul('Update Record');
          nul('Delete Record');
          nul('Search');
          nul('View all Records'); ?>
    </table>
    <?php // ========================================================
  }
  // ================================================================ ?>
  <p><strong>MORE PHP</strong></p>
  <table cellpadding="0" cellspacing="0" border="0" width="100%">
  <?php 
    nav('../phpconsole/', 'PHP&nbsp;Console&nbsp;Apps'); 
    nav('../phpweb/', 'PHP&nbsp;Web&nbsp;Apps'); 
  ?>
  </table>