php 二级菜单
下边这段二级下拉菜单连动下拉,是读取数据库修改产品页时的代码,第一级下拉能读取一级分类数据,但第二级二拉只能再选过一次,要怎改为也可以自动获取二级分类呢?<script language="javascript">var subcat2 = new Array();<?phprequire('config.php');$i=0;$sql="select * from p_cclass ";//查询所有小类$result=MySQL_query($sql);while($rs=mysql_fetch_array($result)){echo "subcat2[".$i++."] = new Array('".$rs["cc_id"]."','".$rs["cid_ccid"]."','".$rs["classname"]."');\n";}?>function changeselect1(locationid){document.myform.cc_id.length = 0;document.myform.cc_id.options[0] = new Option('暂无二级分类','');//alert(subcat2[1].toString());//alert(locationid.length.toString());for (i=0; i<subcat2.length; i++){if (subcat2[i][1] == locationid){document.myform.cc_id.options[document.myform.cc_id.length] = new Option(subcat2[i][2], subcat2[i][0]);}document.myform.cc_id.options[0] = new Option('==请选择二级分类==','');}}</script><form action="pro_edit.php" method="post" name="myform" id="myform" > <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#F1F5F8"><tr><td width="697" height="51"><table width="100%" height="175" border="0" cellpadding="0" cellspacing="0"><tr><td height="31" colspan="2" align="center" bgcolor="#D6E7F7">修改产品</td></tr><tr><td width="65" height="26"> 产品类型:</td><td width="632" height="26"><select name="c_id" id="c_id" onChange="changeselect1(this.value)" style="width:100;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff"><?phprequire("config.php"); //包含文件$p_id=$_GET["p_id"];$sqlp = "select * from product where p_id='$p_id'"; $rsp=mysql_query($sqlp); $rscountp=mysql_fetch_array($rsp);$c_id=$rscountp["p_cid"];$sql="select * from p_class where c_id='$c_id'";//查询表$rs=mysql_query($sql);$rscount=mysql_fetch_array($rs)?><option value="<?=$rscount["c_id"]?>"><?=$rscount["classname"]?></option><?php$sqln="select * from p_class where c_id!='$c_id'";//查询表$rsn=mysql_query($sqln);while($rscountn=mysql_fetch_array($rsn)){ ?><option value="<?=$rscountn["c_id"]?>"><?=$rscountn["classname"]?></option><?php}?></select></select><select name="cc_id" id="cc_id" style="width:100;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff"><?php$p_id=$_GET["p_id"];$sqla = "select * from product where p_id='$p_id'"; $rsa=mysql_query($sqla); $rscounta=mysql_fetch_array($rsa);$c_id=$rscounta["p_cid"];$sqlb = "select * from p_class where c_id='$c_id'"; $rsb=mysql_query($sqlb); $rscountb=mysql_fetch_array($rsb);$cid_ccid=$rscountb["c_id"];?><?php$sqlc = "select * from p_cclass where cid_ccid='$cid_ccid'"; //条件小分类$rsc=mysql_query($sqlc); $rscountc=mysql_fetch_array($rsc);?><option value="<?=$rscountc["cc_id"]?>"><?=$rscountc["classname"]?></option><?php$sqla="select * from p_cclass where cid_ccid='$cid_ccid'";//查询表$rsc=mysql_query($sqlc);while($rscountc=mysql_fetch_array($rsc)){ ?><option value="<?=$rscountc["cc_id"]?>"><?=$rscountc["classname"]?></option><?php}?></select></label></td></tr><tr><td height="59" align="center"><input type="submit" name="Submit" value="确定提交" onclick="return Check();" /> <input name="p_id" type="hidden" id="p_id" value="<?=$rscountp["p_id"]?>" /> <input type="reset" name="Submit2" value="重置" /><textarea name="p_content" id="p_content" style="display:none;"><?=$rscountp["p_content"]?></textarea></td></tr></table></form>
- -- 表的结构 `product`-- CREATE TABLE `product` ( `p_id` int(15) NOT NULL AUTO_INCREMENT, `p_name` varchar(100) NOT NULL, `p_cccid` varchar(100) NOT NULL, `p_ccid` varchar(15) NOT NULL, `p_cid` varchar(100) NOT NULL, `p_imgurl` varchar(100) NOT NULL, `p_content` varchar(1000) NOT NULL, `p_number` varchar(15) NOT NULL, `p_sortid` varchar(15) NOT NULL, `p_scroll` varchar(15) NOT NULL DEFAULT '0', `p_sortidd` varchar(15) NOT NULL, PRIMARY KEY (`p_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=31 ;-- -- 导出表中的数据 `product`-- INSERT INTO `product` VALUES (4, '4', '22', '38', '24', 'upload/1287706504.jpg', '你死我活 ', 'PL6389999999999', '0022', '0', '22');INSERT INTO `product` VALUES (6, '6', '19', '36', '23', 'upload/1287706041.bmp', '', 'PL3999555555', '0021', '0', '21');INSERT INTO `product` VALUES (7, '7', '17', '35', '24', 'upload/1287706041.bmp', '', 'PL3999', '0020', '0', '20');INSERT INTO `product` VALUES (8, '8', '', '38', '24', 'upload/20101023124900.jpg', '现在的的很好用 ', 'TCSS36666', '0019', '0', '19');INSERT INTO `product` VALUES (10, '10', '21', '38', '24', 'upload/20101023125120.jpg', '现在的的很好用 ', 'PL336699', '0018', '1', '18');INSERT INTO `product` VALUES (11, '11', '18', '36', '23', 'upload/20101027201020.jpg', '', '23331', '0017', '1', '17');INSERT INTO `product` VALUES (12, '11', '22', '38', '24', 'upload/20101027204003.jpg', '', '54645', '0016', '1', '16');INSERT INTO `product` VALUES (13, 'sdfasdfds', '16', '35', '24', 'upload/20101027204346.jpg', 'sdfsd ', 'asdfasdfsd', '0015', '0', '15');INSERT INTO `product` VALUES (14, 'sefas', '16', '35', '24', 'upload/20101027204531.jpg', 'sdafsd ', 'sdfa', '0014', '0', '14');INSERT INTO `product` VALUES (17, 'sdfds', '22', '38', '24', 'upload/20101027210346.jpg', '', '23331', '0013', '0', '13');INSERT INTO `product` VALUES (18, 'sdfds', '19', '36', '23', 'upload/20101027211354.gif', '', 'asdfasdfsd', '0012', '0', '12');INSERT INTO `product` VALUES (22, 'sdafsd', '21', '38', '24', 'upload/20101027220734.png', 'sdfds ', 'sdfds', '0008', '0', '8');INSERT INTO `product` VALUES (19, 'sdfasdfds', '16', '35', '24', 'upload/20101027213407.gif', 'dfgasd ', 'asdfasdfsd', '0011', '0', '11');INSERT INTO `product` VALUES (20, 'sdfds', '19', '36', '23', 'upload/20101027213430.gif', 'fdgdf ', 'sdf', '0010', '0', '10');INSERT INTO `product` VALUES (21, 'sdfasdfds', '22', '38', '24', 'upload/20101027213538.gif', '', 'dfg', '0009', '0', '9');INSERT INTO `product` VALUES (23, 'sdfsd', '18', '36', '23', 'upload/20101027220752.png', 'sdfds ', 'sdfsd', '0007', '0', '7');INSERT INTO `product` VALUES (24, '电刷', '23', '38', '24', 'upload/20101102132745.jpg', '', 'PL8888', '0006', '1', '6');INSERT INTO `product` VALUES (25, 'sdfasdfds', '19', '36', '23', 'upload/20101102133302.jpg', '', 'PL8888', '0005', '1', '5');INSERT INTO `product` VALUES (26, '12233', '23', '38', '24', 'upload/20101105132946.png', 'fadsfdsfds ', 'dsfdsdsfdsf', '0004', '0', '4');INSERT INTO `product` VALUES (28, 'fsda', '23', '38', '24', 'upload/20101107155144.png', '', 'sdfds', '0003', '0', '3');INSERT INTO `product` VALUES (29, 'AAAAAAA', '16', '35', '24', 'upload/20101109103038.gif', '', '888888888', '0002', '0', '2');INSERT INTO `product` VALUES (30, 'AAAAAAA', '19', '36', '23', 'upload/20101109113914.gif', '', '888888888', '0001', '0', '1');-- ---------------------------------------------------------- -- 表的结构 `public`-- -- 表的结构 `p_ccclass`-- CREATE TABLE `p_ccclass` ( `ccc_id` int(15) NOT NULL AUTO_INCREMENT, `classname` varchar(100) NOT NULL, `sortid` varchar(100) NOT NULL, `cid_ccid_cccid` varchar(100) NOT NULL, PRIMARY KEY (`ccc_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=32 ;-- -- 导出表中的数据 `p_ccclass`-- INSERT INTO `p_ccclass` VALUES (13, '贴片电容', '001', '34');INSERT INTO `p_ccclass` VALUES (14, '钽电容', '003', '34');INSERT INTO `p_ccclass` VALUES (15, '钻头', '001', '35');INSERT INTO `p_ccclass` VALUES (16, '钻线', '003', '35');INSERT INTO `p_ccclass` VALUES (12, '电解电容', '002', '34');INSERT INTO `p_ccclass` VALUES (17, '钻靠', '002', '35');INSERT INTO `p_ccclass` VALUES (18, 'SOC8950', '', '36');INSERT INTO `p_ccclass` VALUES (19, 'TP4471', '', '36');INSERT INTO `p_ccclass` VALUES (20, 'TL317', '', '36');INSERT INTO `p_ccclass` VALUES (21, '机芯', '003', '38');INSERT INTO `p_ccclass` VALUES (22, '线圈', '002', '38');INSERT INTO `p_ccclass` VALUES (23, '电刷', '001', '38');INSERT INTO `p_ccclass` VALUES (30, '手动电P', '', '52');INSERT INTO `p_ccclass` VALUES (31, '电动电P', '', '52');-- ---------------------------------------------------------- -- 表的结构 `p_cclass`-- CREATE TABLE `p_cclass` ( `cc_id` int(15) NOT NULL AUTO_INCREMENT, `classname` varchar(100) NOT NULL, `sortid` varchar(100) NOT NULL, `cid_ccid` varchar(100) NOT NULL, PRIMARY KEY (`cc_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=53 ;-- -- 导出表中的数据 `p_cclass`-- INSERT INTO `p_cclass` VALUES (36, 'IC', '002', '23');INSERT INTO `p_cclass` VALUES (38, '电动机', '002', '24');INSERT INTO `p_cclass` VALUES (52, '电P', '', '23');INSERT INTO `p_cclass` VALUES (35, '电钻配件', '001', '24');-- ---------------------------------------------------------- -- 表的结构 `p_class`-- CREATE TABLE `p_class` ( `c_id` int(15) NOT NULL AUTO_INCREMENT, `classname` varchar(100) NOT NULL, `sortid` varchar(15) NOT NULL, PRIMARY KEY (`c_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=26 ;-- -- 导出表中的数据 `p_class`-- INSERT INTO `p_class` VALUES (23, '电子产品', '001');INSERT INTO `p_class` VALUES (24, '电动工具', '002');
再修改数据的时候你要根据产品的那个分类父ID读取该父ID的子类
然后循环
js触发onchange事件,然后AJAX查询二级分类,JS插入数据
用ajax将二级分类数据取回来插入
还未解决,有代码参考一下吗
还未解决,有代码参考一下吗
参考
上边那段功能已实现了,只是需要修改产品时读取到相关的二级分类,现在修改产品是读不到相关对应的二级分类出来,
上边那段功能已实现了,只是需要修改产品时读取到相关的二级分类,现在修改产品是读不到相关对应的二级分类出来,
没看到我在2#说的话??
在修改数据的时候你要根据产品的那个分类父ID读取该父ID的子类