A PHP/MySQL HierMenus Generation Interface - (2/4) | WebReference

A PHP/MySQL HierMenus Generation Interface - (2/4)

To page 1current pageTo page 3To page 4
[previous] [next]

A PHP - MySQL Interface for HierMenus 4

Installing the Interface

Step 1: Creating the MySQL Database Tables

It is assumed that you know the basics of MySQL. For reference, you may visit their manual available at https://www.mysql.com/documentation/.

If your host allows you to name your own database, lets call it "hiermenu." If not, it doesn't matter, as we will just need two tables in any database that you may have. Apart from the database name, you will, of course, need the MySQL server name, your username and password for access to the database. These will be used to configure the PHP script as explained later. Once you have configured the script correctly, the PHP script will automatically connect to the database when required.

The menu parameters and menu tree information will be kept in two separate tables. I have called them menu_param and menu_tree. The structures of the tables are given below, but you may already have guessed what they will have since you should already know what HierMenus needs.

The field lengths will accommodate the JS expressions that HierMenus allows. If you do not plan to use them, the field lengths can be drastically reduced in length to accommodate just numbers, color codes and logical values. In any case, the table structure can be easily altered even after it is populated provided you know what you are doing.

Table menu_param

FieldType
record_idint unsigned auto_increment
array_suffixvarchar(16)
widthvarchar(125)
left_positionvarchar(125)
top_positionvarchar(125)
font_colorvarchar(20)
mouseover_font_colorvarchar(20)
background_colorvarchar(20)
mouseover_background_colorvarchar(20)
border_colorvarchar(20)
separator_colorvarchar(20)
top_is_permanentvarchar(125)
top_is_horizontalvarchar(125)
tree_is_horizontalvarchar(125)
position_undervarchar(125)
top_more_images_visiblevarchar(125)
tree_more_images_visiblevarchar(125)
evaluate_upon_tree_showvarchar(125)
evaluate_upon_tree_hidevarchar(125)

You can use the following SQL statement to create the table once the database is in use:

CREATE TABLE menu_param (
   record_id int(11) NOT NULL auto_increment,
   array_suffix varchar(16),
   width varchar(125),
   left_position varchar(125),
   top_position varchar(125),
   font_color varchar(20),
   mouseover_font_color varchar(20),
   background_color varchar(20),
   mouseover_background_color varchar(20),
   border_color varchar(20),
   separator_color varchar(20),
   top_is_permanent varchar(125),
   top_is_horizontal varchar(125),
   tree_is_horizontal varchar(125),
   position_under varchar(125),
   top_more_images_visible varchar(125),
   tree_more_images_visible varchar(125),
   evaluate_upon_tree_show varchar(125),
   evaluate_upon_tree_hide varchar(125)
);

Table menu_tree

FieldType
record_idint unsigned auto_increment
array_suffixvarchar(16)
link_namevarchar(64)
urlvarchar(255)
item_is_rolloverenum('0','1')
item_permanently_highlightedenum('0','1')
item_has_childenum('0','1')

You can use the following SQL statement to create the table once the database is in use:

CREATE TABLE menu_tree (
   record_id int(11) NOT NULL auto_increment,
   array_suffix varchar(16),
   link_name varchar(64),
   url varchar(255),
   item_is_rollover enum('0','1'),
   item_permanently_highlighted enum('0','1'),
   item_has_child enum('0','1')
);

Populating the tables

The number of records in each table will depend on your site architecture.

The first field in each table i.e. record_id is not a HierMenus requirement. These will be required for maintenance of the tables. You need a unique id for each record so that you can call it up for deletion, alteration etc. You may first view a list of all records to find out which record you want to modify.

For creating and managing the database you may need an interface like the author's Database Console that you can find at https://www.creativephp.com, unless you want to input directly from MSDOS or UNIX prompt. The console can be used to manage all the databases you may have on different servers.

Examples of data in these tables are:

Table menu_param

FieldRecord 1Record 2
record_id12
array_suffix12
width150100
left_position 200
top_position 50
font_color Blue
mouseover_font_color Gray
background_color Gray
mouseover_background_color Blue
border_color Black
separator_color Black
top_is_permanent 1
top_is_horizontal 1
tree_is_horizontal 0
position_under 1
top_more_images_visible 0
tree_more_images_visible 0
evaluate_upon_tree_show
evaluate_upon_tree_hide

Please note that the menu_param table will have only as many records as are required. This means that it will have a record each for only those menu trees that need to have parameters. You may have guessed that those menu members whose JavaScript arrays have blank arrays as their first elements will not require places in this table.

The record_id will be auto-generated and so you don't need to input any value. You don't need to have values for all fields of a record. The array_suffix is, however, a must. If you don't specify a parameter, the default value of HierMenus will take over. For parent menus the default specified is used and for child menus the parent parameters are defaults.

Table menu_tree

FieldRecord 1Record 2
record_id12
array_suffix11_1
link_nameExperts3-D Animation
urlhttps://webref.com/experts/https://webref.com/3d/
item_is_rollover11
item_permanently_highlighted00
item_has_child10

The same comment goes for record_id here too. For this table all fields are required. The last three will accept only '0' or '1' and the default value is '0.'

How does the program know which parameter set relates to which tree? The link is the array_suffix and that's how PHP pulls out the relevant parameters to load the HierMenus JavaScript variables and arrays.


To page 1current pageTo page 3To page 4
[previous] [next]

Written by J. Chakrabarty and
Created: September 24, 2001
Revised: September 24, 2001


URL: https://webreference.com/programming/php/hierphp/2.html