<?php
mysql_connect("localhost","root","");
$m_quy = mysql_query("show databases;");
$m_row = mysql_num_rows($m_quy);if(!empty($_REQUEST[select1])){
mysql_select_db($_REQUEST[select1]);
$m_quy1 = mysql_query("show tables;");
}
echo "<form name='form1' id='form1'>\n";
echo "<select name='select1' id='select1' onchange='this.form.submit()'>\n";
echo "<option></option>\n";
while($m_value = mysql_fetch_array($m_quy)){
echo "<option value='$m_value[0]'>".$m_value[0]."</option>\n";
}
echo "</select>";
echo "<select name='select2' id='select2'>
echo "<option></option>\n";
while($m_value1 = mysql_fetch_array($m_quy1)){
echo "<option value='$m_value1[0]'>".$m_value1[0]."</option>\n";
}
echo "</select>";
?>
大概是这样,具体你再去调整一下,包括判断是否有选择数据库的判断。

解决方案 »

  1.   

    <?php
    mysql_connect("localhost","root","");
    $m_quy = mysql_query("show databases;");
    $m_row = mysql_num_rows($m_quy);if(!empty($_REQUEST[select1])){
    mysql_select_db($_REQUEST[select1]);
    $m_quy1 = mysql_query("show tables;");
    }
    echo "<form name='form1' id='form1'>\n";
    echo "<select name='select1' id='select1' onchange='this.form.submit()'>\n";
    echo "<option></option>\n";
    while($m_value = mysql_fetch_array($m_quy)){
    $m_sel = '';
    if($_REQUEST[select1]==$m_value[0]){
    $m_sel="selected";
    }
    echo "<option value='$m_value[0]' $m_sel>".$m_value[0]."</option>\n";
    }
    echo "</select>";
    echo "<select name='select2' id='select2'>\n";
    echo "<option></option>\n";
    while($m_value1 = mysql_fetch_array($m_quy1)){
    echo "<option value='$m_value1[0]'>".$m_value1[0]."</option>\n";
    }
    echo "</select>";
    ?>
    改进刷新后可以知道哪个被选中了。
      

  2.   

    给你个2及联动的  数据库类型的   你自己研究一下 很好用的  我现在就是用这个
    原来是省市2及连动菜单
    <?php 
    //连接数据库// country -- 大类表:数据库
    // province -- 小类表:数据表
    // 然后你再把where条件、输出字段等修改一下就基本OK了$query1=mysql_query("select * from country where language_kind = '0' order by id asc"); 
    $fMenu=""; 
    $fValue=""; 
    while($data1=mysql_fetch_array($query1)){ 
    $fMenu.="\"".$data1[name]."\","; 
    $fValue.="\"".$data1[id]."\","; } 
    $fMenu=substr($fMenu,0,(strlen($fMenu)-1)); 
    $fMenu="[".$fMenu."]";//*****************************得到var fMenu 
    $fValue=substr($fValue,0,(strlen($fValue)-1)); 
    $fValue="[".$fValue."]";//*****************************得到var fValue //得到*****************************var sMenu 
    $query1=mysql_query("select * from country where language_kind = '0' order by id asc"); 
    while($data1=mysql_fetch_array($query1)){ 
    $province_id1=$data1[id]; $query2=mysql_query("select * from province where province_id='$province_id1' order by province_id desc"); 
    while($data2=mysql_fetch_array($query2)){ 
    $num=mysql_num_rows($query2); 
    $i++; 
    $sMenu.="\"".$data2[name]."\","; 
    if($i==$num){ 
    $sMenu="[".$sMenu."],["; 
    $i=0; 



    $sMenu.="]"; 
    $sMenu=str_replace("\",]","\"]",$sMenu); 
    $sMenu=str_replace(",[]","]",$sMenu); 
    if((substr($sMenu,0,2))=="[\""){ 
    $sMenu="[".$sMenu; 
    }else{ 
    $sMenu=preg_replace("/\[{3,}/is","[[\\1",$sMenu);//匹配 
    } //得到*****************************var sValue 
    $query1=mysql_query("select * from country where language_kind = '0' order by id asc"); 
    while($data1=mysql_fetch_array($query1)){ 
    $province_id=$data1[id]; $query2=mysql_query("select * from province where province_id='$province_id' order by province_id asc"); 
    while($data2=mysql_fetch_array($query2)){ 
    $nums=mysql_num_rows($query2); 
    $j++; 
    $sValue.="\"".$data2[id]."\","; 
    if($j==$nums){ 
    $sValue="[".$sValue."],["; 
    $j=0; 



    $sValue.="]"; 
    $sValue=str_replace("\",]","\"]",$sValue); 
    $sValue=str_replace(",[]","]",$sValue); 
    if((substr($sValue,0,2))=="[\""){ 
    $sValue="[".$sValue; 
    }else{ 
    $sValue=preg_replace("/\[{3,}/is","[[\\1",$sValue);//匹配 
    } ?> 
    <div id="tar"></div> 
    <SCRIPT LANGUAGE="JavaScript" DEFER> 
    var fMenu = <?php echo $fMenu; ?>; 
    var fValue = <?php echo $fValue; ?>; 
    var sMenu = <?php echo $sMenu; ?>; 
    var sValue = <?php echo $sValue; ?>; var oWhere = document.all.tar; 
    var ofMenu = document.createElement("<SELECT name='bigclass'>"); 
    var osMenu = document.createElement("<SELECT name='smallclass'>"); 
    with(oWhere)appendChild(ofMenu),appendChild(osMenu); createMainOptions(); 
    createSubOptions(0); ofMenu.onchange = function() {createSubOptions(this.selectedIndex);}; function createMainOptions() { 
    for(var i=0;i<fMenu.length;i++)ofMenu.options[i] = new Option(fMenu[i],fValue[i]); 

    function createSubOptions(j) { 
    with(osMenu) { 
    length=0; 
    for(var i=0;i<sMenu[j].length;i++)osMenu.options[i] = new Option(sMenu[j][i],sValue[j][i]); 


    </SCRIPT> 
      

  3.   

    不可能,那俩个我都是本地测试了才传上去的。
    或者你把$_REQUEST[select1]改成$_POST[select1];或者直接就是$select1.
      

  4.   

    好了,两个文件,你放在一个目录下面:main.php
    ---------------------------------------------------------------------------------
    <?php 
    $dbConn = mysql_connect("localhost","root","") or die ("Cannot connect to the db server.");
    $dbsHandler = mysql_list_dbs();
    ?>
    <html>
    <head><title>www.guru21.com</title><script language="javascript">
    <!--
    function refreshTables(dbName){
    document.formRefreshTables.dbName.value = dbName;
    document.formRefreshTables.submit();
    }
    //-->
    </script>
    </head><body><!--- iframe & refresh form declare begin //-->
    <iframe id="frameRefresh" name="frameRefresh" src="about:blank" width="0" height="0" scrolling="no"></iframe>
    <form name="formRefreshTables" action="refresh.php" method="post" target="frameRefresh">
      <input type="hidden" name="dbName">
    </form>
    <!--- iframe & refresh form declare end   //-->Databases: <br/>
    <select name="dbs" id="dbs" onchange="refreshTables(this.value);">
      <option value=""> -- Please Select -- </option>
    <?php
    while ($dbs=mysql_fetch_array($dbsHandler)) {
        echo  '<option value="' . $dbs[0] . '">' . $dbs[0] . '</option>';
    }
    ?>
    </select>
    <br/><br/>Tables: <br/>
    <div id="tableList"></div>
    </body>refresh.php
    ---------------------------------------------------------------------------------
    <?php 
    $dbConn = mysql_connect("localhost","root","") or die ("Cannot connect to the db server.");// get the db name from the hidden field
    $dbName = trim($_POST["dbName"]);
    $tablesHandler = mysql_list_tables($dbName);$html = '<select name="tables" id="tables" size="10">';
    while ($tables=mysql_fetch_array($tablesHandler)) {
    $html .= '<option value="' . $tables[0] . '">' . $tables[0] . '</option>';
    }
    $html .= '</select>'; 
    ?><script language="javascript">
      parent.document.getElementById("tableList").innerHTML = '<?php echo $html; ?>';
    </script>-------------------------
    IE & FireFox 下面测试通过
      

  5.   

    to how9s(农民工), 为了吃牛肉,为什么非要杀头牛呢?