WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PHP 5 Menu Objects Extended
Categories : PHP, PHP Classes, Databases, MySQL Click here to Update Your Picture
Joseph Crawford
Date : Feb 10th 2005
Grade : 4 of 5 (graded 6 times)
Viewed : 5902
File : 4073.zip
Images : No Images for this code example.
Search : More code by Joseph Crawford
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
Like this code?
Show the author your appreciation.
 

Let me start by saying this will not work out of the box, you will need to create a database object and a user object to work with this code...

when you create the methods for those 2 classes, make sure you edit these 3 menu class files so that the method calls reflect the methods in your user and database class.

Ok so i have expanded on my menu objects. You can now have it be dynamic based on the user level of the user viewing. In my system i have a user object that handles the users, there are several different user levels, they each have a numeric and text label. I store my user levels in a database and then grab them and turn them into constants. So when you see a reference in this code think of a user level say 0 and the text is Guest 1 and text is User etc..

let me start by showing the database scheme and explain them.

The Menu Group Table

CREATE TABLE `menu_groups` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(20) NOT NULL default '',
  `req_level` int(2) NOT NULL default '0',
  `login_display` int(1) NOT NULL default '0',
  `display_order` int(2) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;


id = the group id (obviously)
title = the textual name of the group
req_level = the required user level in integer format
login_display = show this group if the user is logged in? 0/1 format
display_order = the order in which to display this group



The Menu Items Table
CREATE TABLE `menu_items` (
  `id` int(11) NOT NULL auto_increment,
  `mgroup` int(11) NOT NULL default '0',
  `title` varchar(20) NOT NULL default '',
  `link` varchar(25) NOT NULL default '',
  `req_level` int(2) NOT NULL default '0',
  `login_display` int(1) NOT NULL default '0',
  `display_order` int(2) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;


id = the item id (obviously)
mgroup = the id of the group this item belongs to
title = the textual name of the item
link = either a filename or a full out url to a page
req_level = the required user level in integer format
login_display = show this group if the user is logged in? 0/1 format
display_order = the order in which to display this item

the display order is an integer format you can use to set the order of display 1,2,3,4,5,6,7,8,9 etc,,, if you have 2 items and you set the display order to be 10,100 the one with the lowest order is shown first.

ok so with that explained let's move on to the actual code in this small application.

<?php

// include the class file.
include_once( 'Menu.class.php' );

// create an instance of the object.
$menu = new Menu( $db_object );

// place this wherever you want to draw the menu
$menu->Draw( $user_object );

?>


Here is an example menu (user not logged in)

General
Home
FAQ
Rules
Control Panel
Login
Register


Here is an example menu (user logged in)

General
Home
FAQ
Rules
Staff
Community
Forums
Chat Stats
Live Chat
Control Panel
Logout

Notice how Login and Register are no longer shown. This is because i have them set in the database. I have set the login_display to 0 so that they would not be shown.

Attached you will find the 3 class files for the menu object.

As always, any questions or need help getting this started just email me



MySQL Handler
Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes
Simple Mini Poll class library (SimPoll)
Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs
Simple usersOnline class - keep track of how many users are online on your site
Categories : PHP, PHP Classes, Databases, MySQL
PostGreSQL and MySQL 2 in 1 db Manager
Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL
PHP Object Example of the Perl DBI with MySQL
Categories : PHP, PHP Classes, MySQL, Databases, Perl
[PHP5] aDB PDO LIKE Database Abstraction. Switch easily from one db server to another, strong errors management, manage transactions, queries preparation and more.
Categories : PHP, PHP Classes, Databases, MS SQL Server, MySQL
Password reminder
Categories : PHP, PHP Classes, Databases, MySQL, Mail
Online Automatic Class Generator for MySQL Tables
Categories : PHP, PHP Classes, Classes and Objects, Databases, MySQL
Specify your connection settings and create a link to a MySQL database.
Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides
MySQL Connection/Query Class
Categories : Databases, MySQL, PHP, PHP Classes
phpFormGenerator for Dynamic Form Generation from MySQL
Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP
DBXML- A Class to backup databases in XML Format using web interface
Categories : PHP, PHP Classes, Databases, MySQL, XML
MySQL Class to ease Database connectivity
Categories : MySQL, PHP Classes, Databases, PHP
Create and restore backup of MySQL databases
Categories : MySQL, Databases, PHP, PHP Classes, Complete Programs
This class splits the results of the query into multiple pages like what the search engine does.
Categories : PHP Classes, PHP, MySQL, Databases