http://www.csdn.net/expert/topic/974/974562.xml?temp=.3960382这是我以前回答的一个问题.跟你一样.看看你会找到答案.

解决方案 »

  1.   

    这不是PHP能做的,是要用javascript做的,PHP只是负责取数据,如果你一定要用PHP做,那也可以啊,刷新
      

  2.   

    TO phpteam(George):用javascript是怎样做呀?我不会呀!TO anziqi(安子琦):那篇文章很难看呀!
      

  3.   

    <javascript>
    //&cedil;&Atilde;&ordm;&macr;&Ecirc;&yacute;&Oacute;&Atilde;&Oacute;&Uacute;&sup2;ú&Eacute;ú&Ograve;&raquo;&cedil;&ouml;&Ograve;&raquo;&Icirc;&not;&Ecirc;&yacute;×é&pound;&not;&micro;&laquo;&Ograve;&raquo;°&atilde;&Oacute;&Atilde;&Euml;ü×&ouml;&Ntilde;&shy;&raquo;·&sup2;ú&Eacute;ú&Ograve;&raquo;&cedil;&ouml;&micro;&Uacute;&Ograve;&raquo;&cedil;&ouml;&Iuml;&Acirc;±ê&Icirc;&ordf;&Ecirc;&yacute;&Ouml;&micro;&pound;&not;&micro;&Uacute;&para;&thorn;&cedil;&ouml;&Iuml;&Acirc;±ê&iquest;&Eacute;&Icirc;&ordf;'Data','Value','aText'&micro;&Auml;&para;&thorn;&Icirc;&not;&Ecirc;&yacute;×é&iexcl;&pound; 
    function aClass(aData, aValue, aText) {
     if (aClass.arguments.length < 3)
          alert("&acute;&laquo;&Egrave;&euml;&micro;&Auml;&sup2;&Icirc;&Ecirc;&yacute;&acute;í&Icirc;ó&pound;&iexcl;")
        else {
          this.Data  = aData;    //&sup2;ú&Eacute;ú&micro;&Auml;&frac12;&laquo;&Ecirc;&Ccedil;&micro;&Uacute;&Ograve;&raquo;&cedil;&ouml;&Iuml;&Acirc;&Agrave;&shy;&iquest;ò&micro;&Auml;value
          this.Value = aValue;   //&sup2;ú&Eacute;ú&micro;&Uacute;&para;&thorn;&cedil;&ouml;&iquest;ò&micro;&Auml;value&Ouml;&micro;
          this.Text  = aText;    //&sup2;ú&Eacute;ú&micro;&Uacute;&para;&thorn;&cedil;&ouml;&iquest;ò&micro;&Auml;text&Auml;&Uacute;&Egrave;&Yacute;
        }
      }
    //&cedil;&Atilde;&ordm;&macr;&Ecirc;&yacute;&Oacute;&Atilde;&Oacute;&Uacute;&micro;&Atilde;&micro;&frac12;&micro;&Uacute;&Ograve;&raquo;&cedil;&ouml;&Iuml;&Acirc;&Agrave;&shy;&iquest;ò±&raquo;&Ntilde;&iexcl;&Ouml;&ETH;&para;&Ocirc;&Iuml;ó&micro;&Auml;value&Ouml;&micro;
    //&pound;¨aSrc=&micro;&Uacute;&Ograve;&raquo;&cedil;&ouml;&Iuml;&Acirc;&Agrave;&shy;&iquest;ò&para;&Ocirc;&Iuml;ó&pound;&raquo;aDes=&micro;&Uacute;&para;&thorn;&cedil;&ouml;&Iuml;&Acirc;&Agrave;&shy;&iquest;ò&para;&Ocirc;&Iuml;ó&pound;&raquo;aClass&Oacute;&Atilde;&Eacute;&Iuml;&Atilde;&aelig;&ordm;&macr;&Ecirc;&yacute;&sup2;ú&Eacute;ú&micro;&Auml;&Ecirc;&yacute;×é&pound;&raquo;&pound;&copy;
      function chgDnCombobox(aSrc, aDes, aClass, aRemain){   
        if (chgDnCombobox.arguments.length < 3)
          alert("&acute;&laquo;&Egrave;&euml;&micro;&Auml;&sup2;&Icirc;&Ecirc;&yacute;&acute;í&Icirc;ó&pound;&iexcl;")
        else if (aSrc.type != "select-one")  //&Aring;&ETH;&para;&Iuml;&Iuml;&Acirc;&Agrave;&shy;&iquest;ò&Ecirc;&Ccedil;&sup2;&raquo;&Ecirc;&Ccedil;&micro;&yen;&Ntilde;&iexcl;&iquest;ò
          alert("&acute;&laquo;&Egrave;&euml;&micro;&Auml;&sup2;&Icirc;&Ecirc;&yacute;&acute;í&Icirc;ó&pound;&iexcl;")
        else if (aClass == null)
          alert("aClass&Icirc;&acute;&para;¨&Ograve;&aring;&acute;í&Icirc;ó&pound;&iexcl;")
        else {
          if (aRemain==null)
            aRemain = 1;
          chgDnComboboxItem(aSrc.options[aSrc.selectedIndex].value, aDes, aClass, aRemain);
        }
      }  function chgDnComboboxItem(aValue, aDes, aClass, aRemain){
        if (chgDnComboboxItem.arguments.length<3)
          alert("&sup2;&Icirc;&Ecirc;&yacute;&acute;&laquo;&Egrave;&euml;&acute;í&Icirc;ó&pound;&iexcl;")
        else if (aClass==null)
          alert("&acute;í&Icirc;ó&pound;&iexcl;aClass&Atilde;&raquo;&Oacute;&ETH;&para;¨&Ograve;&aring;&pound;&iexcl;")
        else{
          if (aRemain==null)
            aRemain = 1;
          deleteAllComboboxItem(aDes, aRemain); //&Eacute;&frac34;&sup3;&yacute;&micro;&Uacute;&para;&thorn;&cedil;&ouml;&Iuml;&Acirc;&Agrave;&shy;&iquest;ò&micro;&Auml;&Euml;ù&Oacute;&ETH;option&para;&Ocirc;&Iuml;ó
          for (var i=0; i<aClass.length; i++)
            if (aClass[i].Data==aValue)  /* check aClass[i].Data */
              if (aClass[i].Data!="")
                addComboboxItem(aDes, aClass[i].Text, aClass[i].Value);//&Eacute;ú&sup3;&Eacute;&micro;&Uacute;&para;&thorn;&cedil;&ouml;&Iuml;&Acirc;&Agrave;&shy;&iquest;ò&micro;&Auml;option&para;&Ocirc;&Iuml;ó
    }
      }
    //&Eacute;&frac34;&sup3;&yacute;&micro;&Uacute;&para;&thorn;&cedil;&ouml;&Iuml;&Acirc;&Agrave;&shy;&iquest;ò&micro;&Auml;&Euml;ù&Oacute;&ETH;option&para;&Ocirc;&Iuml;ó
      function deleteAllComboboxItem(aList, aRemain) {
      for (var i=aList.options.length; i > aRemain; i--)
          aList.options[i] = null;
      }    
    //&Eacute;ú&sup3;&Eacute;&micro;&Uacute;&para;&thorn;&cedil;&ouml;&Iuml;&Acirc;&Agrave;&shy;&iquest;ò&micro;&Auml;option&para;&Ocirc;&Iuml;ó
      function addComboboxItem(aList, aText, aValue) {
        var aOption = new Option(aText, aValue);
      aList.options[aList.options.length]=aOption;  }
    ///PHP拿数具
    var f_Set0 = new Array(
    <?php
    for($i=0;$i<$stateRow;$i++)
    {
      echo "new aClass('".$state->result[$i][country]."', '".$state->result[$i][state]."', '".$state->result[$i][state]."'),";
    }
      echo "new aClass('".$state->result[$i][country]."', '".$state->result[$i][state]."', '".$state->result[$i][state]."')"
    ?>
    );
    function change_area(aForm) {
    chgDnCombobox(aForm.country, aForm.state, f_Set0 , 0)
    }</javascript>互动框
    <select name="country" onChange="change_area(document.dataform)">
                            <option value="NULL">--- 
                            <?php echo $Select;?>
                            ---</option>
                            <?php
    for ($i=0;$i<$countryRow;$i++)
    if ($currCompany->result[0][country]==$country->result[$i][country])
    echo "<option value=\"".$country->result[$i][country]."\" selected>".$country->result[$i][description]."</option>";
    else
    echo "<option value=\"".$country->result[$i][country]."\">".$country->result[$i][description]."</option>";
    ?>
                          </select>根据国家改变省洲,看见SQL部份是拿数据的,你要根据你自己的情况去拿
    这里主要用到的是javascript
     <select name="state">
                            <option value="NULL">--- 
                            <?php echo $Select;?>
                            ---</option>
                            <?php
    for ($i=0;$i<$stateRow;$i++)
    if ($currCompany->result[0][state]==$state->result[$i][state])
    echo "<option value=\"".$state->result[$i][state]."\" selected>".$state->result[$i][state]."</option>";
    else
    echo "<option value=\"".$state->result[$i][state]."\">".$state->result[$i][state]."</option>";
    ?>
                          </select>
      

  4.   

    这个也太烦了,我有简单很多的javascript程序
      

  5.   

    <?
       require("conn.php");
       $sql="select * from table1";
       $ro=mysql_query($sql);
     ?>
    <html>
    <head>
    <title>新闻添加</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <script language="javascript">
    <!--
        function check(){
             if(document.form1.news_title.value=="")
             {
                 alert("警告:\n没有填写新闻标题!")
                 document.form1.news_title.select()
                 return false
                 }
             if(document.form1.news_sort.value==-1)
             {
                 alert("警告:\n没有选择新闻分类!")
                 document.form1.news_sort.focus()
                 return false
                 }
             if(document.form1.city.value==-1)
             {
                 alert("警告:\n没有选择新闻二级分类!")
                 document.form1.city.focus()
                 return false
                 }
             if(document.form1.news_message.value=="")
             {
                 alert("警告:\n没有填写新闻内容!")
                 document.form1.news_message.select()
                 return false
                 }
             
         document.form1.submit()
        return true
        }
       function cls()
    {
          document.form1.news_title.value=""
      document.form1.news_author.value=""
      document.form1.news_message.value=""
     
       }
     function change_area()
    {
    var item_title = new Array;
    <?
    $j=0;
    while($rp=mysql_fetch_array($ro))
    {
    $kk= "\"".$rp["sort_name"]."&".$rp["sort_name1"]."\"\n";
    ?>
    item_title[<?echo $j;?>]=<? echo $kk;?>
    <?
    $j=$j+1;
    }
    ?>
    if (document.form1.city.value!="-1")
    {
         for(var i=0;i<document.form1.city.length;i++)
         { 
            document.form1.city.options[0]= null;
         }
    }
    var menu;
    var j;
    j=0;
    for(var i=0;i<item_title.length;i++)
    {
      menu=item_title[i].split("&");
      if(menu[0]==document.form1.news_sort.value)
        {
    document.form1.city.options[j]= new Option(menu[1],menu[1]);
    j++;
       }
    }
    if(j==0) 
    {
        document.form1.city.options[0]= new Option("----请选择分类----","-1");
    }
    }
    //-->
    </script><link rel="stylesheet" href="../../css/1.css" type="text/css">
    </head><body bgcolor="#cccccc" text="#000000" topmargin="0"  leftmargin="0">
    <form name="form1" enctype="multipart/form-data" method="post" action="savenew.php?mode=ok" onSubmit="return check();">
    <?include("news_title.php")?>
      <table width="80%" border="0" cellspacing="0" cellpadding="0" align="center" class="word">
        <tr> 
          <td> &nbsp;&nbsp;&nbsp;
            <center>
              <b>新闻添加 </b>
    </center>
          </td>
          <td rowspan="2">&nbsp;</td>
        </tr>
        <tr>
          <td>
            <div align="right">说明:带<font color="#FF0000">*</font>为必填项</div>
          </td>
        </tr>
        <tr valign="top"> 
          <td height="211"> 
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="3%" height="214">&nbsp;</td>
                <td width="97%" height="214" valign="top" bgcolor="#F7F7F7"> 
                  <table width="100%" border="1" bgcolor="#cccccc" bordercolorlight="#000000" cellspacing="0" bordercolordark="#FFFFFF" cellpadding="0" class="word">
                    <tr> 
                      <td width="19%"> 
                        <div align="center">新闻标题<font color="#FF0000">*</font>:</div>
                      </td>
                      <td width="76%"> 
                        <input type="text" name="news_title" size="50">
                      </td>
                    </tr>
                    <tr> 
                      <td width="19%"> 
                        <div align="center">新闻作者:</div>
                      </td>
                      <td width="76%"> 
                        <input type="text" name="news_author">
                      </td>
                    </tr>
                    <tr> 
                      <td width="19%"> 
                        <div align="center">新闻分类<font color="#FF0000">*</font>:</div>
                      </td>
                      <td width="76%"> 
                        <select name="news_sort" size=1 onChange="change_area()">
                          <option value="-1" selected>----请选择分类----</option>
                          <?
      $sql="select * from table";
              $ry=mysql_query($sql);
      while($rl=mysql_fetch_array($ry))
      {
      ?>
                          <option value="<?echo $rl["sort_id"];?>"> 
                          <?echo $rl["sort_name"];?>
                          </option>
                          <?
      }
      ?>
                        </select>
                        <a href="news_sort.php" class="word">&lt;&lt;&lt;添加分类 </a> </td>
                    </tr>
                    <tr> 
                      <td width="19%" height="13"> 
                        <div align="center">二级分类<font color="#FF0000">*</font>:</div>
                      </td>
                      <td width="76%" height="13"> 
                        <select name="city" size=1 >
                          <option value="-1" selected>----请选择分类----</option>
                        </select>
                        <a href="news_sort1.php" class="word">&lt;&lt;&lt;添加二级分类</a> </td>
                    </tr>
                    <tr> 
                      <td width="19%" height="7"> 
                        <center>
                          新闻专集
    </center>
                      </td>
                      <td width="76%" height="7">
                        <select name="new_group">
    <option value="">---请选择新闻专集---</option>
         <?
     $sqll="select group_name,group_code from news_group";
     $rtk=mysql_query($sqll);
     while($rpl=mysql_fetch_array($rtk))
     {
     ?>
                          <option value="<?echo $rpl["group_code"];?>"><?echo $rpl["group_name"];?></option>
      <?
      }
      ?>
                        </select>
                      </td>
                    </tr>
                    <tr> 
                      <td width="19%" height="7">
                        <center>
                          新闻图片: 
                        </center>
                      </td>
                      <td width="76%" height="7">
                        <input type="file" name="pic" size="30">
                      </td>
                    </tr>
                    <tr> 
                      <td height="12" valign="top"> 
                        <div align="center">新闻内容<font color="#FF0000">*</font>:</div>
                        <div align="center">&nbsp;</div>
                      </td>
                      <td> 
                        <textarea name="news_message" cols="50" rows="9"></textarea>
                      </td>
                    </tr>
                    <tr> 
                      <td width="19%"> 
                        <div align="center">首页显示:</div>
                      </td>
                      <td width="76%"> 
                        <input type="radio" name="news_on" value="0" checked>
                        显示 
                        <input type="radio" name="news_on" value="1">
                        不显示 </td>
                    </tr>
                    <tr> 
                      <td width="19%"> 
                        <center>
                          语 种: 
                        </center>
                      </td>
                      <td width="76%"> 
                        <input type="radio" name="lan" value="ch" checked>
                        中文 
                        <input type="radio" name="lan" value="en">
                        英文</td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
          <td height="211" width="5%">&nbsp;</td>
        </tr>
        <tr> 
          <td colspan="2"> 
            <center>
              <input type="submit" name="Submit" value="添加">
              <input type="reset" name="Submit2" value="取消">
            </center>
          </td>
        </tr>
      </table>
    </form></body>
    </html>
      

  6.   

    如果数据量很大,建议用隐藏桢或者xmlhttp来取第二层数据
      

  7.   

    <form name=form1 action="">
    <select name="select1" onchange="document.form1.submit()">
    <option value="computer1">computer1</option>
    <option value="computer2">computer2</option>
    </select>
    <?
    $sql=mysql_query("select * from table where computer='$select1'");
    $num=mysql_numrows($sql);
    if($num){
    ?>
    <select name="select2">
    <option value="字段值">字段值</option>
    </select>
       <?
        }
     ?>
    </form>
      

  8.   

    俺是第N次看到类似问题了,哈哈给你个结构清晰的参考,自己根据需要修改吧<select id=oSel1 onchange=Chg()>
    <option> CPU
    <option> 硬盘
    <option> 主板
    </select>
    <select id=oSel2>
    </select><script>//二维数据表格(二维数组)
    var Table2dim = new Array(
        new Array("Intel PIII", "AMD Athlon", "Intel Celoron"),
        new Array("IBM", "Westwood", "Quantum"),
        new Array("Asus", "Gigabyte"),
        null
    );//Chg() 和 ChgOptions(i) 都是通用的,只要修改上面的 oSel1 的选项和 Table2dim 的内容即可
    function Chg()
    {
        ChgOptions(document.all.oSel1.selectedIndex);
    }
    function ChgOptions(iSel1)
    {
        if ( 0 <= iSel1 && iSel1 < Table2dim.length )
        {
            var oSel2 = document.all.oSel2, i;        //删除所有旧选项(不知道有没有不用循环的删除办法)
            for ( i = oSel2.options.length; -- i >= 0; )
                oSel2.options.remove(i);        //创建新关联选项
            var Table1dim = Table2dim[iSel1];
            for ( i = 0; i < Table1dim.length; i ++ )
            {
                var o = document.createElement('<option>');
                o.text = Table1dim[i];
                oSel2.options.add(o);
            }
        }
    }//初始化
    ChgOptions(0);
    </script>
      

  9.   

    alexxing(赤铸) 说的很对
    上一次我就用的他的方法,很好的
    现在我还很感激他啊
      

  10.   

    俺没注意:是要用PHP做。前面一部分:<select id=oSel1 onchange=Chg()>
    <option> CPU
    <option> 硬盘
    <option> 主板
    </select>
    <select id=oSel2>
    </select><script>//二维数据表格(二维数组)
    var Table2dim = new Array(
        new Array("Intel PIII", "AMD Athlon", "Intel Celoron"),
        new Array("IBM", "Westwood", "Quantum"),
        new Array("Asus", "Gigabyte"),
        null
    );可以用PHP从数据库中取出数据动态生成
    (把后面的函数放到单独的.JS文件中,可以提高速度)我的方法只适合于数据量有限的情况,但是简单如果你有几百种零配件,几百种CPU,就最好用PHP动态交互实现SELECT的更新,这就复杂多了,需要用一个隐藏帧在“幕后”与服务器交互取得数据,再用DHTML更新SELECT的内容