加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

php 三级联动菜单

发布时间:2021-07-23 20:33:52 所属栏目:Asp教程 来源:互联网
导读:-- 表的结构 `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`)


-- 表的结构 `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 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 onChange="changelocation2(document.myform.smallclassid.options[document.myform.smallclassid.selectedIndex].value)" size="1">
<option selected value="">请指定二级分类</option>
</select>
<select size="1">
<option selected value="">==所有三级分类==</option>
</select>

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读