框架代码,实现细节需要自己写
sample
test.php
<?php
if (isset($_POST["testselect1"])){
    //判断第一个select的值
    $select1= $_POST["testselect1"];
    //构造第二个select
    while () {
        $select2="<option value='$key'>$value</option>"
    }
}
?>
<form action="" name="test" action="POST">
<SELECT onchange="forms.test.submit()" name="testselect1"> 
<option value="1">1</option> 
<option value="2">2</option> 
</SELECT>
<select name="testselect2">
<?php echo @$select2; ?>
</select>
</form>

解决方案 »

  1.   

    根据你的实际情况来做
    实际上这个可以做成无极分类
    #-----------------------------------------------------<script language = "JavaScript">
    var onecount;
    onecount=0;
    subcat = new Array();
    <?
    mysql_select_db( $db_name );
    $sql = "select * from $tablepre WHERE FatherID > 0 AND open = '1'";
    $result = mysql_query( $sql );
    $count = 0;
    while($res = mysql_fetch_row($result)){
    ?>
    subcat[<? echo $count; ?>] = new Array("<? echo $res[2]; ?>","<? echo $res[1]; ?>","<? echo $res[0]; ?>");
    <?
    $count++;
    }
    echo "onecount=$count";
    ?>function changelocation(locationid)
    {
    document.myform.TypeAddSmall.length = 0; var locationid=locationid;
    var i;
    for (i=0;i < onecount; i++)
    {
    if (subcat[i][1] == locationid)
    {
    document.myform.TypeAddSmall.options[document.myform.TypeAddSmall.length] = new Option(subcat[i][0], subcat[i][2]);
    }
    }}
    </script>#---------------------------------------------------------------<form action="?" name="myform" method="post"><select class="BgInput" name="type" onChange="changelocation(document.myform.type.options[document.myform.type.selectedIndex].value)" size="1">
    <option selected value="">-- 选择大类 --</option>
    <?
    $sqlI = "select * from $tablepre where FatherID = 0";
    $resultI = mysql_query( $sqlI );
    while($resI = mysql_fetch_row($resultI)){
    ?>
    <option value="<? echo $resI[0]; ?>"><? echo $resI[2]; ?></option>
    <? } ?>
    </select>
    <select class="Submit" name="TypeAddSmall">
      <option selected value="">请指定小分类</option>
    </select></form>
      

  2.   

    lucidaxy() :$_POST只有在表单提交以后才能调用,我试了一下没成
      

  3.   

    <Select onchange="location.href='xx?id=xxxx'">
    提交一个 参数就行了
      

  4.   

    当然,select 1页面是在初始化的时候初始化,select 2是经由select 1触发的post事件触发。这个方法是服务器端实现逻辑
    客户端实现方法可参照 gzty(风逍遥)的方法
    基本上就这两种实现方法
    to:  aniude(阿牛的乜乜)
    用post方法无需附加参数可获得 select 值