|
|
|
| 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.
<?
// 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>";
?>
| |
|
|
|