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 : 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 19 times)
Viewed : 35344
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  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>"
;


?>



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
Linked comboboxes with php-mysql & javascript
Categories : PHP, Java Script, Databases, MySQL
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
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
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
Pull Down Surfing - Surf on Change
Categories : Java Script, MySQL, HTML and PHP, PHP, Databases
Complex paging with no resultset limit
Categories : PHP, MySQL, Databases, Output Control, HTML and PHP
for each record, do this to the first record, and do that to any subsequent record
Categories : PHP, Databases, MySQL, Beginner Guides
Dynamically generated pop-ups (Select items)
Categories : PHP, HTML and PHP, MySQL, Databases
database,php,mysql,demo,example,php3,training,tutorial,codes,code
Categories : Databases, MySQL, PHP, PHP Options and Info
Displaying records of database in more than one page (paging)
Categories : Databases, MySQL, PHP
phpFormGenerator for Dynamic Form Generation from MySQL
Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP
MySQL Class to ease Database connectivity
Categories : MySQL, PHP Classes, Databases, PHP
Zip code range and distance calculation class v1.0.0
Categories : PHP, Databases, MySQL, Zip Code
 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;