PHP Level Two Linkage menu

Source: Internet
Author: User

<?php
PHP section:
Get the pull down linkage data
Require ("conn.php");
$result =mysql_query ("SELECT * from units left JOIN the users on (Users.unit=units.unid)");
$mx =mysql_num_rows ($result);

for ($i =0; $i < $mx; $i + +) {
$r =mysql_fetch_array ($result);
$uname = $r [' uname '];
$unid = $r [' Unid '];
$usname = $r [' username '];
$usid = $r [' userid '];

if ($lasun!= $uname) {
$java 1= $java 1. "$uname", ";
$java 2= $java 2. "$unid", ";
$lasun = $uname;
if ($i >0) {
$java 3= $java 3. "],[";
$java 4= $java 4. "],[";
}
} else {
$java 3= $java 3. ",";
$java 4= $java 4. ",";
}

$java 3= $java 3. "" $usname "";
$java 4= $java 4. "" $usid "";

}

$java 1 = "[".   Substr_replace ($java 1, "",-1). "]n";
$java 2 = "[".   Substr_replace ($java 2, "",-1).   "]n";
$java 3 = "[[].   $java 3. "]]n";
$java 4 = "[[].   $java 4. "]]n";



JavaScript section
?>
<script language= "JavaScript" defer>
var fmenu = <?= $java 1?>
var fvalue = <?= $java 2?>
var smenu = <?= $java 3?>
var svalue = <?= $java 4?>

var owhere = Document.all.tar;
var ofmenu = document.createelement ("<select name= ' Unid ' >");
var osmenu = document.createelement ("<select name= ' Usid ' >");
With (Owhere) appendchild (Ofmenu), appendchild (Osmenu);

Createmainoptions ();
Createsuboptions (0);

Ofmenu.onchange = function () {createsuboptions (this.selectedindex);};

function Createmainoptions () {
for (Var i=0;i<fmenu.length;i++) ofmenu.options[i] = new Option (fmenu[i],fvalue[i));
}
function Createsuboptions (j) {
With (Osmenu) {
length=0;
for (Var i=0;i<smenu[j].length;i++) osmenu.options[i] = new Option (smenu[j][i],svalue[j][i));
}
}

function checkuser () {
if (document.forms[1].elements[1].value== "") {alert ("No user selected");   return false; }
}
</SCRIPT>

<!--referencing--> in HTML
<div id= "tar" style= "Display:inline" ></div>
<!--
Additional data table structure with users and units
Table Users:
Userid
Username
Unit

Table units:
Unid
Uname

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.