PHP二级下拉菜单连动问题
本帖最后由 gdljw 于 2013-09-13 17:13:20 编辑 下边这段二级下拉菜单连动下拉,是读取数据库修改产品页时的代码,第一级下拉能读取一级分类数据,但第二级二拉只能再选过一次,要怎改为也可以自动获取二级分类呢?
<script language="javascript">
var subcat2 = new Array();
<?php
require('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">
<?php
require("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>