php 三級聯動菜單

來源:互聯網
上載者:User

資料庫結構
複製代碼 代碼如下:-- 表的結構 `bigclass`
--
CREATE TABLE `bigclass` (
`bigclassid` int(11) NOT NULL auto_increment,
`bigclassname` varchar(200) collate utf8_unicode_ci NOT NULL,
`sort` int(11) NOT NULL,
`suoshu` int(1) NOT NULL,
PRIMARY KEY (`bigclassid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=19 ;
-- 表的結構 `smallclass`
--
CREATE TABLE `smallclass` (
`smallclassid` int(11) NOT NULL auto_increment,
`smallclassname` varchar(200) collate utf8_unicode_ci NOT NULL,
`bigclassid` int(11) NOT NULL,
`sort` int(11) NOT NULL,
PRIMARY KEY (`smallclassid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=7 ;
-- 表的結構 `minclass`
--
CREATE TABLE `minclass` (
`minclassid` int(10) NOT NULL auto_increment,
`minclassname` varchar(200) NOT NULL,
`bigclassid` int(10) NOT NULL,
`smallclassid` int(10) NOT NULL,
`sort` int(10) NOT NULL,
PRIMARY KEY (`minclassid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

代碼如下 複製代碼 代碼如下:<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<?
//類別選擇
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?>
//聯動函數
function changelocation(bigclassid)
{
document.myform.smallclassid.length = 0;
var bigclassid=bigclassid;
var i;
document.myform.smallclassid.options[0] = new Option('請選擇二級分類','');
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);
$sql2 = "select * from minclass order by sort";
$result2 = mysql_query( $sql2 );
$count2 = 0;
?>
<script language = "JavaScript">
//如果這個數組中含有雙引號則不能使用。即二級和三級類不能含有雙引號
var onecount2;
onecount2=0;
subcat2 = new Array();
<?php
$count2 = 0;
while($res2 = mysql_fetch_row($result2)){
?>
subcat2[<?php echo $count2?>] = new Array("<?php echo $res2[1]?>","<?php echo $res2[3]?>","<?php echo $res2[0]?>");
<?php
$count2++;
}
?>
onecount2=<?php echo $count2?>;
function changelocation2(smallclassid)
{
document.myform.minclassid.length = 0;
var smallclassid=smallclassid;
var j;
document.myform.minclassid.options[0] = new Option('請選擇三級分類','');
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="">請指定一級分類</option>
<?
$sql = "select * from bigclass order by sort";
$result = mysql_query( $sql );
while($res = mysql_fetch_row($result)){
?>
<option value="<? echo $res[0]; ?>"><? echo $res[1]?></option>
<? } ?>
</select>
<select name="smallclassid" onChange="changelocation2(document.myform.smallclassid.options[document.myform.smallclassid.selectedIndex].value)" size="1">
<option selected value="">請指定二級分類</option>
</select>
<select name="minclassid" size="1">
<option selected value="">==所有三級分類==</option>
</select>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.