Php > Databases
Building dynamic menus with PHP & MySQL (ADO), JavaScript and CSS
Building dynamic menus with PHP & MySQL (ADO), JavaScript and CSS // Create database and table code for MySQL below //CREATE DATABASE [dbname] //CREATE TABLE `menu` ( // `id` int(3) NOT NULL default '0', // `menu_item` varchar(32) NOT NULL default '', // PRIMARY KEY (`id`) //) TYPE=MyISAM; // Stylesheet code below (inline or external works fine) ?> // ADO Connection description $db = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=127.0.0.1;DATABASE=dbname;UID=user;PWD=password; OPTION=35"; // Create connection object $conn = new COM("ADODB.Connection") or die("Cannot start ADO"); // Open the database $conn->Open($db); // Execute the query $rs = $conn->Execute("SELECT id, menu_item FROM menu ORDER by id;"); // Get section / menu name $section = $_REQUEST['section']; // Remove URL encoded chars $decoded = rawurldecode($section); // Remove white spaces from menu item for JavaScript to handle preg_replace('/.\s/', '', $decoded); // Build the memu echo "
"; while (!$rs->EOF) { echo "
Fields[menu_item]->Value) { echo " class='out' onMouseOver=\"this.className='over'\" onMouseOut=\"this.className='out'\" onMouseDown=\"this.className='down'\" onClick=\"location.href='" . $PHP_SELF . "?sctn=" . $rs->Fields[menu_item]->Value . "&id=" . $rs->Fields[id]->Value . "';\"> " . $rs->Fields[menu_item]->Value . "
\n"; } else { echo " class='out'> " . $rs->Fields[menu_item]->Value . " \n"; } $rs->MoveNext(); } echo "\n" . "
"; ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage