PHP Three-Level linkage menu _ Practical Tips

Source: Internet
Author: User
Database structure
Copy Code code as follows:

--The structure of the table ' Bigclass '
--
CREATE TABLE ' Bigclass ' (
' Bigclassid ' int (one) not NULL auto_increment,
' bigclassname ' varchar collate utf8_unicode_ci not NULL,
' Sort ' int (one) not NULL,
' Suoshu ' int (1) Not NULL,
PRIMARY KEY (' Bigclassid ')
) Engine=myisam DEFAULT Charset=utf8 collate=utf8_unicode_ci auto_increment=19;
--The structure of the table ' Smallclass '
--
CREATE TABLE ' Smallclass ' (
' Smallclassid ' int (one) not NULL auto_increment,
' smallclassname ' varchar collate utf8_unicode_ci not NULL,
' Bigclassid ' int (one) is not NULL,
' Sort ' int (one) not NULL,
PRIMARY KEY (' Smallclassid ')
) Engine=myisam DEFAULT Charset=utf8 collate=utf8_unicode_ci auto_increment=7;
--The structure of the table ' Minclass '
--
CREATE TABLE ' Minclass ' (
' Minclassid ' int (a) not NULL auto_increment,
' minclassname ' varchar not NULL,
' Bigclassid ' int (a) not NULL,
' Smallclassid ' int (a) not NULL,
' Sort ' int (a) not NULL,
PRIMARY KEY (' Minclassid ')
) Engine=myisam DEFAULT charset=latin1 auto_increment=3;

The code is as follows
Copy Code code as follows:

<script language = "JavaScript" >
var Onecount;
onecount=0;
subcat = new Array ();
?
Category Selection
mysql_select_db ($database _lr, $LR);
$sql = "SELECT * from Smallclass order by sort";
$result = mysql_query ($sql);
$count = 0;
while ($res = Mysql_fetch_row ($result)) {
?>
subcat[<?= $count] = new Array ("<?= $res [1]?>", "<?= $res [4]?>", "<?= $res [0]?>");
?
$count + +;
}
?>
onecount=<?php Echo $count?>
linkage function
function Changelocation (BIGCLASSID)
{
document.myform.smallclassid.length = 0;
var Bigclassid=bigclassid;
var i;
Document.myform.smallclassid.options[0] = new option (' Please select Class two ', ');
For (I=0;i < onecount; i++)
{
if (subcat[i][1] = = Bigclassid)
{
Document.myform.smallclassid.options[document.myform.smallclassid.length] = new Option (subcat[i][0], subcat[i][2]) ;
}
}
}
</script>
<?php
mysql_select_db ($database _lr, $LR);
$sql 2 = "SELECT * from Minclass order by sort";
$result 2 = mysql_query ($sql 2);
$count 2 = 0;
?>
<script language = "JavaScript" >
If the array contains double quotes, it cannot be used. Class Two and level three cannot contain double quotes
var Onecount2;
onecount2=0;
SUBCAT2 = new Array ();
<?php
$count 2 = 0;
while ($res 2 = mysql_fetch_row ($result 2)) {
?>
subcat2[<?php echo $count 2?>] = new Array ("<?php echo $res 2[1]?>", "<?php Echo $res 2[3]?>", "<?php echo $res 2[0]?> ");
<?php
$count 2++;
}
?>
onecount2=<?php Echo $count 2?>;
function Changelocation2 (SMALLCLASSID)
{
document.myform.minclassid.length = 0;
var Smallclassid=smallclassid;
var J;
Document.myform.minclassid.options[0] = new option (' Please select Class three ', ');
For (J=0;j < Onecount2; j + +)
{
if (subcat2[j][1] = = Smallclassid)
{
Document.myform.minclassid.options[document.myform.minclassid.length] = new Option (subcat2[j][0], subcat2[j][2]);
}
}
}
</script>
<select name= "Bigclassid" onchange= changelocation (document.myform.bigclassid.options[ Document.myform.bigclassid.selectedindex].value) "size=" 1 ">
<option selected value= "" > Please specify a level of classification </option>
?
$sql = "SELECT * from Bigclass order by sort";
$result = mysql_query ($sql);
while ($res = Mysql_fetch_row ($result)) {
?>
<option value= ". echo $res [0];?> "&GT;&LT;? Echo $res [1]?></option>
? }?>
</select>
<select name= "Smallclassid" onchange= Changelocation2 (document.myform.smallclassid.options[ Document.myform.smallclassid.selectedindex].value) "size=" 1 ">
<option selected value= "" > Please specify Class two </option>
</select>
<select name= "Minclassid" size= "1" >
<option selected Value= "" >== All level three classifications ==</option>
</select>

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.