PHP版的三级联动选择
时间:2009-07-17 来源:hkebao
之前有发过PHP二级菜单
http://www.corange.cn/archives/2008/12/2857.html
和ASP三级联动菜单 http://www.corange.cn/archives/2006/08/15.html
这几天用到了三级联动,将asp的版本改为PHP的了
特地发出来,经过corange.cn测试过了。
数据库结构
-- 表的结构 `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 ;
代码如下
<?php
mysql_select_db($database_lr, $lr);
$sql2 = "select * from minclass order by sort";
$result2 = mysql_query( $sql2 );
$count2 = 0;
?>
<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>
转载请保留版权,本文首发于corange.cn http://www.corange.cn/archives/2009/07/3294.html
http://www.corange.cn/archives/2008/12/2857.html
和ASP三级联动菜单 http://www.corange.cn/archives/2006/08/15.html
这几天用到了三级联动,将asp的版本改为PHP的了
特地发出来,经过corange.cn测试过了。
数据库结构
-- 表的结构 `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 ;
代码如下
<?php
mysql_select_db($database_lr, $lr);
$sql2 = "select * from minclass order by sort";
$result2 = mysql_query( $sql2 );
$count2 = 0;
?>
<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>
转载请保留版权,本文首发于corange.cn http://www.corange.cn/archives/2009/07/3294.html
相关阅读 更多 +