PHP
  Home arrow PHP arrow Page 5 - Dynamic Generation of Menu Structures ...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Dynamic Generation of Menu Structures and JavaScript Rollovers in PHP
By: Chris Mospaw
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 9
    1999-05-10

    Table of Contents:
  • Dynamic Generation of Menu Structures and JavaScript Rollovers in PHP
  • Making a Template
  • Starting to Automate
  • The power of repetition
  • Ordering up a Menu
  • Adding Pages

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Dynamic Generation of Menu Structures and JavaScript Rollovers in PHP - Ordering up a Menu


    (Page 5 of 6 )

    Now that the JavaScript is properly generated, the page needs a complimentary menu structure for the links to other pages. Let's dive right into the code, replacing the "2 - Menu Area" text with:

    <? $i = 0; do { $item = $i + 1; if ($site_pages[$i] == $page) { echo "<img name=\"image" . $item . "\" src=\"$site_pages[$i]-in.gif\" alt=\"" . $site_pages[$i] . ".html\" width=100 height=15 border=0></a><BR>\n"; }else { echo " <a href=\"$site_pages[$i].html\" onMouseOver=\"changeImages('image" . $item . "', 'image" . $item . "on', 'otherImage', 'otherImage" . $item . "')\" "; echo " onMouseOut=\"changeImages('image" . $item . "', 'image" . $item . "off', 'otherImage', 'otherImageDefault')\">"; echo " <img name=\"image" . $item . "\" src=\"$site_pages[$i]-off.gif\" alt=\"" . $site_pages[$i] . ".html\" width=100 height=15 border=0></a><BR>\n"; } $i++; }while ($i < $counter); ?>

    It sure does look complicated, but it's pretty much the same HTML anchor tag we put in the TEMPLATE.HTML file above, but parsed to see if the array element is the current page, and with a whole bunch of escape characters and PHP variables.

    This code uses the $COUNTER variable defined earlier in the script in another DO loop, and generates the appropriate HTML code with JavaScript support. Line 7 introduces another graphic file, FOO-IN.HTML, which is the "third" button file, the other two being FOO-ON.HTML and FOO-OFF.HTML referenced already in the JavaScript.

    The only part left to do is add the HTML line referencing the graphic panel that changes when hovering over the buttons:


    <img name="otherImage" src="default.gif" alt=" " width=100 height=100 border=0><BR>

    This file can actually be put anywhere in the page, but for the sake of simplicity I put it in the menu structure for this example. Since it is referenced by the "NAME" attribute, this is all that is needed to use this graphic in the onMouseOver effects. JavaScript takes care of the rest.

    More PHP Articles
    More By Chris Mospaw


     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT