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 Pull Down Surfing - Surf on Change Categories : Java Script , MySQL , HTML and PHP , PHP , 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 Loading Images to/from MySQL Categories : Databases , MySQL , PHP , Graphics MySQL Connection/Query Class Categories : Databases , MySQL , PHP , PHP Classes How to thread a list of messages in database
and show it in a treelike structure Categories : PHP , MySQL , Databases MySQL Handler Categories : PHP , Databases , MySQL , Classes and Objects , PHP Classes Phorum, MySQL, Language, UK date format, MySQL UK Date format Categories : PHP , Date Time , Strings , MySQL , Databases Checks Date-Input from HTML-Forms and converts to YYYY-MM-DD Format for MySQL Date-Fields Categories : MySQL , Date Time , PHP , Databases PHP4 AND MySQL Authentication Categories : PHP , MySQL , Authentication , Databases Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP , Arrays , Date Time , Databases , MySQL
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.
<?
// Close and release recordset
$rs->Close();
$rs->Release();
$rs = null;
// Close and release connection object
$conn->Close();
$conn->Release();
$conn = null;
?>
<?
$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 "<table width=`75%` border=`0` cellpadding=`0` cellspacing=`0` style=`font-size:10px;font-family:arial`><tr>";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "
<td width=`1`></td>
<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] . "`;\">$row[menu_item]</td>";
} else {
echo " class=`out`>" . $row[menu_item] . "</td>";
}
}
echo "<script language=\"JavaScript\">\n" .
"document.all." . str_replace(" ", "", $decoded) . ".className=`over`;\n" .
"</script>\n" .
"</tr>";
mysql_free_result($result);
echo "<tr>
<td width=`100%` colspan=`20` height=`12` bgcolor=`9EB5E9`></td>
</tr>
</table>";
?>