WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
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
Submit Site
Forex Trading Online forex trading platform

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 : Building dynamic menus with PHP & MySQL (ADO), JavaScript and CSS
Categories : PHP, Databases, MySQL, Java Script, User Interface Click here to Update Your Picture
Michael Quinn
Date : Apr 16th 2004
Grade : 3 of 5 (graded 14 times)
Viewed : 18623
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Michael Quinn
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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;




<?php
// Stylesheet code below (inline or external works fine)
?>
<HTML>
<HEAD>
    <STYLE>
        .out {
         border:0px;
         background-color: #6633CC;
         color: #FFEEFF;
         cursor: hand;
        }
         
        .over {
         background-color: #9EB5E9;
         color: #FFFFFF;
         font-size: 10px;
         cursor: default;
        }

        .down {
         background-color: #CFCFEF;
         color: #666666;
           
         cursor: default;
        }
    </STYLE>
</HEAD>
<BODY>
<?php
// 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 "<table width='70%' border='0' cellpadding='0' cellspacing='0' class='tny'><tr>";

while (!
$rs->EOF) {
               
     echo
"<td style='width:1px;'></td>
           <td id='"
. str_replace(" ", "", $rs->Fields[menu_item]->Value) . "' width='95' height='15' align='center'";         
     if (
$section != $rs->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 . " </td>\n";
     } else {
         echo
" class='out'> " . $rs->Fields[menu_item]->Value . " </td>\n";
     }         
   
$rs->MoveNext();
}

echo
"<script language=\"JavaScript\">\n" .
     
"document.all." . str_replace(" ", "", $decoded) . ".className='over';\n" .
     
"</script>\n" .
     
"</tr>
     </table>"
;


?>



Pull Down Surfing - Surf on Change
Categories : Java Script, MySQL, HTML and PHP, PHP, Databases
Linked comboboxes with php-mysql & javascript
Categories : PHP, Java Script, Databases, MySQL
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
A Complete table(ADD,EDIT,VIEW,DELETE) management System PHP,MYSQL, JAVASCRIPT
Categories : PHP, MySQL, Java Script, Databases
A Simple sign up script with PHP and JavaScript validations.
Categories : PHP, Java Script, MySQL, Databases
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
AJAX Data Grid System using php and mysql. A complete login system with the ability to display data in a grid using ajax. Add , update and delete the records without reloading the page.
Categories : PHP, AJAX, Databases, MySQL, Java Script
Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs.
Categories : Databases, PHP, MySQL, Complete Programs
Cut your MySQL Connections to 1 line of code
Categories : PHP, Beginner Guides, Databases, MySQL
phpAds, a complete banner and ad management system with detailled tracking and stats.
Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases
Point and Click Interface ala MS Access for creating SQL statements.
Categories : MySQL, Complete Programs, General SQL, PHP, Databases
Message of the Day - Random Message (Needs MySQL!)
Categories : Databases, HTML and PHP, PHP, MySQL
Alternating background color for HTML table rows
Categories : PHP, Databases, MySQL, HTML and PHP
color codes for positive and negative numbers
Categories : PHP, MySQL, Databases, HTML
Authorize Me! An authentication script.
Categories : MySQL, Databases, Authentication, PHP
 Sten Johnsen wrote : 1073
What are the included components?
I`ve tried installing the ADOdb package - but there are still bits missing I think..
Otherwise a promising script :-)
 
 Michael Quinn wrote :1074
Hi Sten,

This should work on Linux (I haven`t tested it yet) but definitely works on Windows using just the MySQL functions.  Use the same style info as before and the colspan on the last table definition should be set to the number of returned items from the database.

BTW on the first script I added it may be an idea to close and destroy the connection object and the recordset or you will eventually kill MySQL.

&lt;?
// Close and release recordset
$rs-&gt;Close();
$rs-&gt;Release();
$rs = null;

// Close and release connection object
$conn-&gt;Close();
$conn-&gt;Release();
$conn = null;
?&gt;


&lt;?
$section = $_REQUEST[`sctn`]; // Get section

$id = $_REQUEST[`id`]; // Get ID

$decoded = rawurldecode($section);

$link = mysql_connect("localhost", "root", "password") or die("DATABASE ERROR:");

mysql_select_db("usit") or die("DB SELECT FAILED");                                                             

$query = "SELECT id, menu_item FROM menu ORDER BY id;";

$result = mysql_query($query);

print "&lt;table width=`75%` border=`0` cellpadding=`0` cellspacing=`0` style=`font-size:10px;font-family:arial`&gt;&lt;tr&gt;";

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
     echo "
           &lt;td width=`1`&gt;&lt;/td&gt;
           &lt;td id=`" . str_replace(" ", "", $row[menu_item]) . "` width=`95` height=`15` align=`center`";             
     if ($section != $row[menu_item]) {     
        echo " class=`out`
                onMouseOver=\"this.className=`over`\"
               onMouseOut=\"this.className=`out`\"
                onMouseDown=\"this.className=`down`\"
                onClick=\"location.href=`" . $PHP_SELF . "?sctn=" . $row[menu_item] . "&id=" . $row[id] . "`;\"&gt;$row[menu_item]&lt;/td&gt;";
     } else {
         echo " class=`out`&gt;" . $row[menu_item] . "&lt;/td&gt;"; 
     }             
}

echo "&lt;script language=\"JavaScript\"&gt;\n" .
     "document.all." . str_replace(" ", "", $decoded) . ".className=`over`;\n" .
     "&lt;/script&gt;\n" .
     "&lt;/tr&gt;";

mysql_free_result($result);

echo "&lt;tr&gt;
       &lt;td width=`100%` colspan=`20` height=`12` bgcolor=`9EB5E9`&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;";
?&gt;